我想画一个包含很多饼图的图形。
通常很容易根据矩阵制作热图。
但现在我想使用更好的方法来可视化我的数据。
这是一种我认为还可以但并不完美的方法:
library(ggplot2)
library(gridExtra) # For arranging plots
#library(ChIPseeker)
library(dplyr)
library(plyr )
#??dlply
# Simulate some data
set.seed(123)
data <- expand.grid(X = factor(1:20), Y = factor(1:18))
data$Category <- rep(c("A", "B", "C"), each = 120)
data$Value <- runif(360)
# View the data
print(data)
# Function to plot a pie chart for each group
plot_pie <- function(data_subset) {
ggplot(data_subset, aes(x = "", y = Value, fill = Category)) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") +
theme_void()+
theme(legend.position = "none")
#labs(title = paste("X:", unique(data_subset$X), "Y:", unique(data_subset$Y)))
}
# Split data by X and Y, create a list of plots
plots <- dlply(data, .(X, Y), plot_pie)
# Arrange plots in a grid
grid.arrange(grobs = plots, ncol = 20)
###############
library(patchwork)
# Combine plots with patchwork
plot_layout <- wrap_plots(plots, ncol = 20)
plot_layout
还没有完成,下一步我会在这里添加百分比和一些其他信息,例如行间隙或列间隙。
所以在这里我希望有人给我一些建议或者告诉我更好的方法。
非常感谢。