编辑:问题是由于我错误地尝试改变theme(title = element_text()),当我需要改变时theme(plot.title(element_text()).我会注意到这是我更仔细地审查theme()文档.
原帖:
更改标题垂直对齐也会改变x和y轴标签的位置.这是一个错误吗?还是我误解了theme()的功能?我正在运行ggplot2版本0.9.3.1
最小的可重复的例子.
require(ggplot2)
set.seed(12345)
x <- rnorm(100,10,0.5)
y <- x * 3 + rnorm(100)
df <- data.frame(y,y)
Run Code Online (Sandbox Code Playgroud)
根据我的口味,默认标题太靠近图表....
ggplot(df,aes(x,y)) +
geom_point() +
labs(title="My Nice Graph")
Run Code Online (Sandbox Code Playgroud)

当我尝试移动标题时,轴标签也会移动,并在图形上难以绘制.
ggplot(df,aes(x,y)) +
geom_point() +
labs(title="My Nice Graph") +
theme(title = element_text(vjust=2))
Run Code Online (Sandbox Code Playgroud)

Ric*_*rta 25
你想plot.title不title:
labs(title="My Nice Graph") + theme(plot.title = element_text(vjust=2))
Run Code Online (Sandbox Code Playgroud)
替代快速修复是添加换行符:
labs(title="My Nice Graph\n")
Run Code Online (Sandbox Code Playgroud)
vjust对我不起作用(我也认为值应该在[0,1]中).我用
... +
theme(
plot.title = element_text(margin=margin(b = 10, unit = "pt"))
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19436 次 |
| 最近记录: |