# Install packages
if (!requireNamespace("plotrix", quietly = TRUE)) {
install.packages("plotrix")
}if (!requireNamespace("ggplotify", quietly = TRUE)) {
install.packages("ggplotify")
}
# Load packages
library(plotrix)
library(ggplotify)
3D Pie
Hiplot website
This page is the tutorial for source code version of the Hiplot 3D Pie
plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
The 3D pie chart is a pie chart that has a 3D appearance.
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
plotrix
;ggplotify
Data Preparation
The loaded data are different groups and their data.
# Load data
<- read.delim("files/Hiplot/138-pie-3d-data.txt", header = T)
data
# Convert data structure
colnames(data) <- c("Group", "Value")
$Value <- as.numeric(data$Value)
data<- data[data$Value != 0,]
data
# View data
head(data)
Group Value
1 Group1 13
2 Group2 34
3 Group3 21
4 Group4 43
Visualization
# 3D Pie
pie3D(data$Value, radius = 0.8, height = 0.05, theta = 0.8,
labels = paste(data$Group, "\n(n=", data$Value, ", ",
round(data$Value / sum(data$Value) * 100, 2), "%)",
sep = ""),
explode = 0.1, main = "", labelcex = 1, shade = 0.4, labelcol = "black",
col = c("#E64B35FF","#4DBBD5FF","#00A087FF","#3C5488FF"))

The figure shows more aesthetically the number of samples in groups 1 to 4 and the proportion corresponding to the number of samples in the 3D form. The number of samples in one group is 13, accounting for 11.71%; the number of samples in two groups is 34, accounting for 30.63%; the number of samples in three groups is 21, accounting for 18.92%; and the number of samples in four groups is 43, accounting for 38.74%.