我正在阅读this question和this other question about using \nand expressionin ggplot2axis labels,但它似乎不适用于标题(或多行表达式)。
我原来的情节如下:
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="")))
Run Code Online (Sandbox Code Playgroud)
但是标题太长,所以我尝试使用atop引用问题中推荐的命令放置两个断行:一个在vs和the之间,第二个在model和(0h vs 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=""))))
Run Code Online (Sandbox Code Playgroud)
我得到了标题的这种奇怪行为:
我怎样才能得到一个三行并居中的标题思想?
更新:
用户Shirin 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"))
Run Code Online (Sandbox Code Playgroud)
此代码的结果为标题添加了更多空间,但标题未显示属性:
小智 2
您需要增加上边距。另外,表达式与换行符的配合也不佳。尝试这个:
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"))
Run Code Online (Sandbox Code Playgroud)
我只是添加theme(plot.margin=unit(c(4,0,0,0),"cm"))和删除了里面的粘贴命令expression()。您可以通过 来设置表达式中的新行","。
| 归档时间: |
|
| 查看次数: |
2368 次 |
| 最近记录: |