【发布时间】:2017-09-18 11:54:04
【问题描述】:
我正在寻找一种方法,在图例中拥有两个或更多段以及箱线图的中位数。 我想出了以下示例:
y = data.frame(runif(500))
library(ggplot2)
ggplot(data = y )+
aes(0, y)+
geom_boxplot(outlier.shape = 1)+
scale_y_continuous(name = "",limits = c(0,1))+
scale_x_discrete(name = "")+
geom_segment( aes(x=-0.362, y=0.6, xend=0.363,yend=0.6, linetype = "R
fans"), linetype = "dashed", colour = "black")+
geom_segment( aes(x=-0.35, y=0.8, xend=0.35,yend=0.8, linetype =
"frustated R users"), col = "red" )+
theme_bw()+
theme(legend.title = element_blank())+
theme(legend.background = element_rect(fill="white",
size=0.1, linetype="solid",
colour ="black"))
y=0.6 的 geom_segment 应在图例中以黑色虚线表示。目前我选择了两次线型,这没有意义,但是如果我擦除第二个线型,图例中的颜色会变为红色,或者线型会变为另一种不需要的线型。对于情节和图例,它应该是黑色和虚线。对于 y = 0.8,它工作得很好,因为默认情况下线型是正确的。
另外,我想在图例中添加第三行。第三条线应该是中线,是一条实心粗黑线。
提前感谢您的帮助。
【问题讨论】: