X 和 Y 标签没有出现在我的 ggplot 上
X and Y Labels Not Appearing on my ggplot
我可以为图表添加标题,但 x 和 y 标签没有显示。相反,我得到了底部的计数图例。
pl <- ggplot(movies, aes(x = rating))
pl2 <- pl + geom_histogram(binwidth = 0.1, aes(fill = ..count..))
pl2
pl3 <- pl2 + xlab('Movie Rating') + ylab('Count')
pl3
pl3 + ggtitle('MY TITLE')
这是图表的图片link:
我做错了什么?
您似乎正在使用 ggthemes::theme_fivethirtyeight()
作为 ggplot
主题。此主题的轴标签设置为默认不显示。您可以使用 theme(axis.title = element_text())
:
重新打开它们
library(ggplot2)
library(ggthemes)
theme_set(theme_fivethirtyeight())
pl <- ggplot(mtcars, aes(x = disp)) +
geom_histogram(binwidth = 0.1, aes(fill = ..count..)) +
xlab('Movie Rating') +
ylab('Count') +
ggtitle('MY TITLE')
# Current plot, no labels
pl
# Turn the labels on
pl +
theme(axis.title = element_text())
我可以为图表添加标题,但 x 和 y 标签没有显示。相反,我得到了底部的计数图例。
pl <- ggplot(movies, aes(x = rating))
pl2 <- pl + geom_histogram(binwidth = 0.1, aes(fill = ..count..))
pl2
pl3 <- pl2 + xlab('Movie Rating') + ylab('Count')
pl3
pl3 + ggtitle('MY TITLE')
这是图表的图片link:
我做错了什么?
您似乎正在使用 ggthemes::theme_fivethirtyeight()
作为 ggplot
主题。此主题的轴标签设置为默认不显示。您可以使用 theme(axis.title = element_text())
:
library(ggplot2)
library(ggthemes)
theme_set(theme_fivethirtyeight())
pl <- ggplot(mtcars, aes(x = disp)) +
geom_histogram(binwidth = 0.1, aes(fill = ..count..)) +
xlab('Movie Rating') +
ylab('Count') +
ggtitle('MY TITLE')
# Current plot, no labels
pl
# Turn the labels on
pl +
theme(axis.title = element_text())