# Install packages
if (!requireNamespace("ggstatsplot", quietly = TRUE)) {
install.packages("ggstatsplot")
}if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}if (!requireNamespace("cowplot", quietly = TRUE)) {
install.packages("cowplot")
}
# Load packages
library(ggstatsplot)
library(ggplot2)
library(cowplot)
Piestats Group
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
ggstatsplot
;ggplot2
;cowplot
Data Preparation
# Load data
<- read.delim("files/Hiplot/069-ggpiestats-group-data.txt", header = T)
data
# Convert data structure
<- c("genre", "mpaa")
axis 1]] <- factor(data[, axis[1]], levels = unique(data[, axis[1]]))
data[, axis[2]] <- factor(data[, axis[2]], levels = unique(data[, axis[2]]))
data[, axis[
# View data
head(data)
title year length budget rating
1 Shawshank Redemption, The 1994 142 25 9.1
2 Lord of the Rings: The Return of the King, The 2003 251 94 9.0
3 Lord of the Rings: The Fellowship of the Ring, The 2001 208 93 8.8
4 Lord of the Rings: The Two Towers, The 2002 223 94 8.8
5 Pulp Fiction 1994 168 8 8.8
6 Schindler's List 1993 195 25 8.8
votes mpaa genre
1 149494 R Drama
2 103631 PG-13 Action
3 157608 PG-13 Action
4 114797 PG-13 Action
5 132745 R Drama
6 97667 R Drama
Visualization
# Piestats Group
<- unique(data[,axis[2]])
g <- list()
plist for (i in 1:length(g)) {
<- data[,axis[2]] == g[i]
fil <-
plist[[i]] ggpiestats(
data = data[fil,], x = genre,
title= paste('', axis[2], g[i], sep = ':'),
plotgrid.args = list(ncol = 3),
label.repel = TRUE,
k = 2
+
) scale_fill_manual(values = c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF",
"#008280FF","#BB0021FF","#5F559BFF","#A20056FF",
"#808180FF"))
}
plot_grid(plotlist = plist, ncol = 3)
