![](/img/trans.png)
[英]What function can I use to limit my y-axis in a geom_bar plot?
[英]R geom_bar: How can I return the Y-axis title to my graph?
我正在基于 Rstudio 中内置的 esoph 数据集创建 geom_bar。 起初,该图同时具有 x 轴和 y 轴标题。 但是,当我尝试格式化标题时,Y 轴标题丢失了。 我尝试更改标题的大小,但它再也没有出现。 有人知道如何解决吗?
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.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())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.