[英]Add ylab to ggplot with fivethirtyeight ggtheme
Is it possible to add a label to the y axis if you are using theme_fivethirtyeight
? 如果使用
theme_fivethirtyeight
是否可以在y轴上添加标签? I tried ylab
but it does not work: 我试过
ylab
但它不起作用:
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
. 你可以,但它需要比
ylab
更多的工作,因为你需要更改一些theme
设置,这些设置是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()
. 如果你看一下
theme_fivethirtyeight
的代码(只需在你的控制台中运行theme_fivethirtyeight
来查看代码),你就会看到axis.title
被设置为element_blank()
。 So this theme has no axis titles at all. 所以这个主题根本没有轴标题。 You'll need to change this if you want to set ay axis label.
如果要设置y轴标签,则需要更改此设置。
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. 到你的图表,但你也会得到一个x轴标签。
An alternative would be to use 另一种方法是使用
theme(axis.title = element_text(), axis.title.x = element_blank()) + ylab('Something')
As axis.title.y
inherits from axis.title
, it didn't work to just set axis.title.y
to element_text()
. 由于
axis.title.y
继承自axis.title
,因此无法将axis.title.y
设置为element_text()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.