Is it possible to add a label to the y axis if you are using theme_fivethirtyeight
? I tried ylab
but it does not work:
library(ggplot2)
library(ggthemes)
p2 <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point() +
ggtitle("Cars")
p2 + geom_smooth(method = "lm", se = FALSE) +
scale_color_fivethirtyeight("cyl") +
theme_fivethirtyeight() + ylab('SOMETHING')
You can, but it'll take a bit more work than ylab
because you need to change some of the theme
settings that are the defaults in theme_fivethirtyeight
. If you take a look at the code for theme_fivethirtyeight
(just run theme_fivethirtyeight
in your console to see the code), you'll see that axis.title
is set to element_blank()
. So this theme has no axis titles at all. You'll need to change this if you want to set a y axis label.
For example, you could add
theme(axis.title = element_text()) + ylab('Something')
to your graph, but then you'll get an x axis label, as well.
An alternative would be to use
theme(axis.title = element_text(), axis.title.x = element_blank()) + ylab('Something')
Asaxis.title.y
inherits from axis.title
, it didn't work to just set axis.title.y
to element_text()
.
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