2016-07-28 63 views
1

我讀這個question這等question回合使用\nggplot2軸標籤expression但似乎並不對題(或者多行表達式)工作。多行`表達式()`在GGPLOT2標題

我原來的情節如下:

ggplot(data = fig3, aes(x=crude_beta_time6, y=vidD_beta_time6)) + 
    geom_point(shape=18, size=5, color="gray60") + xlab("Coefficients of the crude model") + 
    ylab(bquote("Coefficients of the total 25(OH)D"[3]~"adjusted model")) + 
    theme_bw(base_size = 17) + theme(
     panel.grid.major = element_line(color = "gray20", size = 0.3, linetype = "dashed"), 
     panel.grid.minor = element_line(color = "gray40", size = 0.3, linetype = "dashed") 
    ) + ggtitle(expression(paste("(B) Coefficients of the crude model vs the total 25(OH)", D[3]," adjusted model (0h vs 6h)", sep=""))) 

enter image description here

但標題太長,所以我試圖用兩個斷裂線所引用的問題建議atop命令到另一個地方:一個之間VS和第二個在模型(0h對6h)

ggplot(data = fig3, aes(x=crude_beta_time6, y=vidD_beta_time6)) + 
    geom_point(shape=18, size=5, color="gray60") + xlab("Coefficients of the crude model") + 
    ylab(bquote("Coefficients of the total 25(OH)D"[3]~"adjusted model")) + 
    theme_bw(base_size = 17) + theme(
     panel.grid.major = element_line(color = "gray20", size = 0.3, linetype = "dashed"), 
     panel.grid.minor = element_line(color = "gray40", size = 0.3, linetype = "dashed") 
    ) + ggtitle(expression(atop(paste("(B) Coefficients of the crude model vs\nthe total 25(OH)", D[3]," adjusted model\n(0h vs 6h)", sep="")))) 

我拿到冠軍的這種奇怪的行爲:

enter image description here

我怎樣才能得到一個三線居中標題思想的表達?

UPDATE

用戶希林Glander建議更新劇情的邊緣,以便使更多的空間爲標題。以下所提供的代碼:

ggplot(data = fig3, aes(x=crude_beta_time6, y=vidD_beta_time6)) + 
geom_point(shape=18, size=5, color="gray60") + xlab("Coefficients of the crude model") + 
ylab(bquote("Coefficients of the total 25(OH)D"[3]~"adjusted model")) + 
theme_bw(base_size = 17) + theme(
    panel.grid.major = element_line(color = "gray20", size = 0.3, linetype = "dashed"), 
    panel.grid.minor = element_line(color = "gray40", size = 0.3, linetype = "dashed")) + 
ggtitle(expression(atop(paste("(B) Coefficients of the crude model vs\nthe total 25(OH)", D[3]," adjusted model\n(0h vs 6h)", sep="")))) + 
theme(plot.margin=unit(c(4,0,0,0),"cm")) 

這段代碼的結果增加了更多的空間爲標題,但標題是未顯示屬性:

enter image description here

回答

0

你需要增加上邊距。然後,表達式在換行符中表現不佳。試試這個:

ggplot(data = fig3, aes(x=crude_beta_time6, y=vidD_beta_time6)) + 
geom_point(shape=18, size=5, color="gray60") + xlab("Coefficients of the crude model") + 
ylab(bquote("Coefficients of the total 25(OH)D"[3]~"adjusted model")) + 
theme_bw(base_size = 17) + theme(
    panel.grid.major = element_line(color = "gray20", size = 0.3, linetype = "dashed"), 
    panel.grid.minor = element_line(color = "gray40", size = 0.3, linetype = "dashed") 
) + ggtitle(expression(atop("(B) Coefficients of the crude model vs", "the total 25(OH)" ~ D[3] ~ "adjusted model (0h vs 6h)"))) + 
theme(plot.margin=unit(c(4,0,0,0),"cm")) 

我只是簡單地添加theme(plot.margin=unit(c(4,0,0,0),"cm"))和刪除內expression()粘貼命令。您可以在","的表達式中設置新的行。

+0

感謝您的回答,但對我而言,這並不奏效。我用另一幅獲得結果的圖片更新了這些問題。雖然頁邊或多或少都是正確設置,但標題沒有正確顯示。 – carlesh