在这个 SO 答案中,用户 @Crops 展示了如何将图例添加到ggalt::geom_dumbbell
绘图中。非常好。
library(ggalt)
df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, 80))
df2 = tidyr::gather(df, group, value, -trt)
ggplot(df, aes(y = trt)) +
geom_point(data = df2, aes(x = value, color = group), size = 3) +
geom_dumbbell(aes(x = l, xend = r), size=3, color="#e3e2e1",
colour_x = "red", colour_xend = "blue",
dot_guide=TRUE, dot_guide_size=0.25) +
theme_bw() +
scale_color_manual(name = "", values = c("red", "blue") )
我想trt
按降序排序r
。我尝试用 替换y = trt
,y = reorder(trt, r)
但我收到一个错误,即r
找不到对象。