【发布时间】:2014-11-05 11:40:15
【问题描述】:
我想在图例中包含均值符号和方框符号。所以我的图例应该包括“曝光 1,曝光 2,曝光 3”,还有意思这个词和它的符号。如何在 R 中使用 ggplot 来做到这一点?
这是我用来制作箱线图的代码:
library(ggplot2)
mydata <- read.csv("~/mydata.csv")
bp<-ggplot(mydata,aes(x=Category,y=MeanValues,,fill=as.factor(Category))) + geom_boxplot()
bp+labs(x = NULL, y = "Result")+ theme_bw()+stat_summary(fun.y = mean, geom = "point",shape = 19, size = 3,show_guide = FALSE)+theme(legend.position="top")+ guides(fill=guide_legend(title=NULL))+ theme(axis.title.y = element_text(size=20, colour = rgb(0,0,0)),axis.text.y = element_text(size=12, colour = rgb(0,0,0)),axis.text.x = element_text(size=12, colour = rgb(0,0,0)))+scale_y_continuous(limits = c(0, 1800), breaks = 0:1800*200)
数据可在https://my.cloudme.com/josechka/mydata获取
上面的代码生成了一个箱线图,箱内有平均值。然而,图例只包含类别的符号。我需要在图例中添加框内的后点代表每个类别的平均值。有可能吗?
【问题讨论】:
-
您能提供到目前为止的代码吗?此外,如果可能,请提供一个图例示例,显示您所描述的内容。