ggplot2 Boxplot值0网格颜色和线型

时间:2016-01-22 15:36:52

标签: r ggplot2 themes boxplot

我想知道如何更改x值= 0的网格线,在图片中用十字标记,在我的图表中显示从+ ive到-ive的变化。我想把它标记为红色,厚度相同。谢谢

===根据评论更新

@Mtoto:道歉。这是脚本。

df.boxplot<- ggplot(melt(df[,c(2:7)]), aes(variable, value)) 
df.boxplot + 
  geom_boxplot(lwd=1.2)+ theme_economist() + scale_colour_economist()+ 
  scale_y_continuous(minor_breaks=seq(-5, 10, 0.5),name="Linear Measurements (mm)", breaks=seq(-5, 10, 1)) +
  theme(axis.title.x = element_text(face="bold", colour="Black", size=20),
        axis.text.x  = element_text(face="bold", colour="Black", vjust=0.5, size=20)) + 
  scale_x_discrete(name="",labels=c("T0 A","T1 B","Δ AB","T0 C","T1 D","Δ CD")) +
  theme(axis.title.y = element_text(face="bold", colour="Black", size=30,margin=margin(0,20,0,0)),
        axis.text.y  = element_text(angle=90, vjust=1, size=20)) + 
  theme(panel.grid.minor = element_line(colour="White",size=0.2))+
  theme(axis.ticks = element_blank())+
  ggtitle(" Title")+
  theme(plot.title = element_text(size=25,lineheight=2, hjust =0.5, vjust=0.5, margin = margin(20, 10, 20, 0)))

我还想在前三个箱图和第二个三个箱图之间添加一个间隙(一个x单位/等级)。我尝试添加NA列并使用drop = FALSE并且它不起作用。

enter image description here

1 个答案:

答案 0 :(得分:1)

我想你想看看geom_hline - 我确定这是重复的......

library(ggplot2)

df <- data.frame(x = gl(5, 25),
                 y = rnorm(125))

ggplot(df, aes(x, y)) +
  geom_boxplot() +
  geom_hline(aes(y_intercept = 0), color = "red")

enter image description here