Edit: The problem was due to my incorrectly attempting to alter theme(title = element_text())
, when I needed to alter theme(plot.title(element_text())
. I would have noticed this had I more carefully scrutinized the theme()
documentation.
Original Post:
Changing the title vertical justification alters the position of the x and y axis labels as well. Is this a bug? Or am I misinterpreting the function of theme()? I am running ggplot2 version 0.9.3.1
Minimal reproducible example.
require(ggplot2)
set.seed(12345)
x <- rnorm(100,10,0.5)
y <- x * 3 + rnorm(100)
df <- data.frame(y,y)
The default title is too close to the graph for my taste....
ggplot(df,aes(x,y)) +
geom_point() +
labs(title="My Nice Graph")
When I try to move the title, the axis labels move also, and illegibly plot on the graph.
ggplot(df,aes(x,y)) +
geom_point() +
labs(title="My Nice Graph") +
theme(title = element_text(vjust=2))
You want plot.title
not title
:
labs(title="My Nice Graph") + theme(plot.title = element_text(vjust=2))
Alternate quick fix is adding a line break:
labs(title="My Nice Graph\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With