2016-01-22 108 views
-1

我想知道如何可以改變x值= 0,標記與所述圖像中的橫格線,在我的圖表表示從+變化香港專業教育學院到-ive。我想有它標記爲紅色與相同厚度。謝謝GGPLOT2箱線圖值0格顏色和線條類型

===基於註釋

@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和使用降= FALSE,並沒有奏效。

enter image description here

+1

例如請 – mtoto

+0

即使你更新後,這是不是[重複性(http://stackoverflow.com/q/5963269/2572423)。在你的例子中'df'是什麼?提供一些示例數據,以便我們可以複製該問題。 – JasonAizkalns

回答

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