对于此数据:
set.seed(123)
df <- data.frame(
ID = 1:50,
Q = rnorm(50),
A = rnorm(50,1)
)
我正在用ggdist
包中的半小提琴绘制一个雨云图:
library(tidyverse)
library(ggdist)
df %>%
pivot_longer(-ID) %>%
ggplot(aes(x = factor(name), y = value, fill = factor(name)))+
# add half-violin
stat_halfeye(
# adjust bandwidth
adjust = 0.5,
# move to the right
justification = -0.2,
# remove the slub interval
.width = 0,
point_colour = NA
)+
geom_boxplot(
width = 0.12,
# removing outliers
outlier.color = NA,
alpha = 0.5
)
结果是这样的:
我如何旋转左半小提琴到相应箱线图的左侧?我尝试使用justification = c(0.2, -0.2)
,但抛出错误。
1条答案
按热度按时间slmsl1lt1#
使用
ifelse
以及justification
和side
美学,您可以执行以下操作: