我有下面的代碼,想知道是否有辦法將箱形圖放在 x 軸或其他包下方。或者通常在 x 軸下方使用白色背景的箱形圖。謝謝!
library(ggstance)
library(ggplot2)
ggplot(diamonds, aes(x = carat, y = -0.5))
# horizontal box plot
geom_boxploth(aes(fill = cut))
# normal density plot
geom_density(aes(x = carat), inherit.aes = FALSE)
# reproduce original chart's color scale (o/w ordered factors will result
# in viridis scale by default, using the current version of ggplot2)
scale_fill_discrete()

uj5u.com熱心網友回復:
你可以使用這個patchwork包:
library(patchwork)
p <- ggplot(diamonds, aes(x = carat, y = -0.5))
p1 <- p geom_density(aes(x = carat), inherit.aes = FALSE)
p2 <- p geom_boxploth(aes(fill = cut))
theme_classic()
theme(axis.text = element_text(color = 'white'),
axis.title = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank())
p1/p2 plot_layout(ncol = 1, nrow = 2, heights = c(2, 1),
guides = 'collect')

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471611.html
下一篇:ggplot標簽顏色基于條件
