[英]Overlay violin plots in r
我試圖在同一變量內按條件繪制疊加小提琴圖。
Var <- rnorm(100,50)
Cond <- rbinom(100, 1, 0.5)
df2 <- data.frame(Var,Cond)
ggplot(df2)+
aes(x=factor(Cond),y=Var, colour = Cond)+
geom_violin(alpha=0.3,position="identity")+
coord_flip()
那么,我在哪里指定我希望它們重疊? 最好是,我希望它們在重疊時變得更亮,在不重疊時變得更暗,這樣它們的區別就很明顯了。 有什么線索嗎?
如果您不希望它們具有不同(翻轉)的 x 值,請將x
設置為常數而不是x = factor(Cond)
。 如果您希望它們被填充,請設置fill
美學。
ggplot(df2)+
aes(x=0,y=Var, colour = Cond, fill = Cond)+
geom_violin(alpha=0.3,position="identity")+
coord_flip()
coord_flip
不再需要了——自 3.3.0 版(2020 年初發布)以來,所有幾何圖形都可以指向任一方向。 我建議簡化如下以獲得類似的結果。
df2$Cond = factor(df2$Cond)
ggplot(df2) +
aes(y = 0, x = Var, colour = Cond, fill = Cond) +
geom_violin(alpha = 0.3, position = "identity")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.