文字最少的一篇哈哈哈褒翰,都是代碼渺杉!
就創(chuàng)建示例數(shù)據(jù)→畫圖→拼圖沦疾,完遼!
data <- data.frame(
Group = rep(c("Group A", "Group B"), each = 100),
Value = c(rnorm(100, mean = 10, sd = 2), rnorm(100, mean = 8, sd = 3))
)
library(ggplot2)
p1 <- ggplot(data, aes(x = Value, fill = Group)) +
geom_density(alpha = 0.5) +
labs(x = "Value", y = "Density") +
theme_minimal()
library(ggpubr)
p2 <- ggplot(data, aes(x = Group, y = Value, fill = Group)) +
geom_boxplot(alpha = 0.5) +
stat_compare_means(label.y = 0)+ #位置換數(shù)據(jù)要調
labs(x = "Group", y = "Value") +
theme_minimal()+
theme(legend.position = "none")+
coord_flip()
library(patchwork)
p1/p2 +
plot_layout(heights = c(2,1),guides = "collect")&
scale_fill_brewer(palette = "Set1")