R 如何更改geom_col中的y_比例?
我正在绘制一个图表,显示0到100之间的比例。y轴上的变量mean_health在70到80之间,因此,我想将刻度限制在该范围内。有人能帮我渡过难关吗 这是我的密码:R 如何更改geom_col中的y_比例?,r,ggplot2,R,Ggplot2,我正在绘制一个图表,显示0到100之间的比例。y轴上的变量mean_health在70到80之间,因此,我想将刻度限制在该范围内。有人能帮我渡过难关吗 这是我的密码: ggplot(a, aes(y=mean_health, fill= Year)) + geom_col(aes(class), position = "dodge") 我试图用下面的线来改变比例,但没有成功: scale_y_continuous(limits = c(70, 80), breaks
ggplot(a, aes(y=mean_health, fill= Year)) +
geom_col(aes(class), position = "dodge")
我试图用下面的线来改变比例,但没有成功:
scale_y_continuous(limits = c(70, 80), breaks = seq(70, 80, by = 2))
以下是我的数据:
structure(list(class = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("Upper-middle class",
"Lower-middle class", "Working class"), class = "factor"), Year = structure(c(1L,
2L, 1L, 2L, 1L, 2L), .Label = c("Prior 2009", "Post 2008"), class = "factor"),
mean_health = c(78.6882398353062, 78.3941867397288, 77.3571107110711,
76.3957410743853, 73.2470989724234, 71.866548366062)), row.names = c(NA,
-6L), groups = structure(list(class = structure(1:3, .Label = c("Upper-middle class",
"Lower-middle class", "Working class"), class = "factor"), .rows = structure(list(
1:2, 3:4, 5:6), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, 3L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
试试这个:
library(ggplot2)
#Code
ggplot(a, aes(y=mean_health, fill= Year)) +
geom_col(aes(class), position = "dodge")+
coord_cartesian(ylim = c(70, 80))+
scale_y_continuous(breaks = seq(70, 80, by = 2))
输出: