2016-07-28 9 views
1

に私が\nggplot2軸ラベルでexpressionを使って試合このquestionこの他questionを読んでいたが、それはタイトルのために(または複数行の表現のために)動作しないようです。複数行 `表現()` 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コマンドを使用して、2つのブレークラインに置くことを試みたです:

私のオリジナルのプロットは、以下の1対間をおよびおよびモデルおよび(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

は、どのように私は3本のラインと中央にタイトルが式を考え得ることができますか?

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