R geom_bar:我如何 return 我的图表的 Y-axis 标题?

R geom_bar: How can I return the Y-axis title to my graph?

我正在基于 Rstudio 中内置的 esoph 数据集创建 geom_bar。起初,该图同时具有 x- 和 y-axis 标题。但是,当我尝试格式化标题时,Y-axis 标题丢失了。我尝试更改标题的大小,但它再也没有出现过。有人知道如何解决它吗?

data(esoph)
data_esoph <- esoph %>% group_by(agegp) %>% 
              summarise(Total_number_of_control_case = sum(ncontrols)) %>% 
              rename(Age_group = agegp)
plot_bar <- data_esoph %>% ggplot(aes(x = Age_group, y = Total_number_of_control_case, fill = Age_group)) +
            geom_bar(stat = "identity", position = "dodge") +
            labs(title ="Number of control cases by age group", subtitle = "Data source: built-in esoph dataset", x = "Age group", y = "Cases", fill = "Age group") +
            geom_text(aes(label = Total_number_of_control_case), vjust = 1.5, colour = "white") +
            theme_cleveland() +
            theme(plot.title = element_text(face = "bold", size = 16, hjust = 0.5), plot.subtitle = element_text(face = "italic", size = 10, hjust = 0.5),
                  axis.title = element_text(face = "bold", size = 10), legend.title = element_text(face = "bold", size = 10)) + 
            scale_fill_jama() 
print(plot_bar)

看起来 theme_cleveland() 的默认设置是删除 y-axis 标签。你确定你需要那个主题吗?如果必须,您需要手动指定 axis.title.y():

data(esoph)
library(dplyr)
library(ggplot2)
library(ggsci)
library(ggpubr)

data_esoph <- esoph %>% group_by(agegp) %>% 
  summarise(Total_number_of_control_case = sum(ncontrols)) %>% 
  rename(Age_group = agegp)

data_esoph %>% ggplot(aes(x = Age_group, y = Total_number_of_control_case, fill = Age_group)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title ="Number of control cases by age group", subtitle = "Data source: built-in esoph dataset", x = "Age group", y = "Cases", fill = "Age group") +
  geom_text(aes(label = Total_number_of_control_case), vjust = 1.5, colour = "white") +
  ggpubr::theme_cleveland() +
  ggsci::scale_fill_jama() +
  theme(plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
        plot.subtitle = element_text(face = "italic", size = 10, hjust = 0.5),
        axis.title = element_text(face = "bold", size = 10),
        legend.title = element_text(face = "bold", size = 10),
        axis.title.y = element_text())