但是现在遇到一个问题是所有的线都变成虚线了,我想要矩形的边框变成实线,那该如何实现呢?经过搜索找到了一个解决办法
链接是
https://stackoverflow.com/questions/53170465/how-to-make-a-base-r-style-boxplot-using-ggplot2
原来有一个函数
stat_boxplot()
可以只画箱线图的矩形,实现代码是
ggplot(HMP,aes(x=country,y=log10(rel_crAss)))+
stat_boxplot(aes(ymin=..lower..,ymax=..upper..))
直接把这个图形叠加到全是虚线边框的箱线图上就可以了
ggplot(HMP,aes(x=country,y=log10(rel_crAss)))+
geom_boxplot(linetype="dashed")+
stat_boxplot(aes(ymin=..lower..,ymax=..upper..))
添加最大值最小值的小横线
ggplot(HMP,aes(x=country,y=log10(rel_crAss)))+
geom_boxplot(linetype="dashed",color="blue")+
stat_boxplot(aes(ymin=..lower..,ymax=..upper..,
fill=country),
color="red")+
stat_boxplot(geom = "errorbar",aes(ymin=..ymax..),
width=0.2,color="red")+
stat_boxplot(geom = "errorbar",aes(ymax=..ymin..),
width=0.2,color="green")