[英]Trying to only display two decades on axis of box-plot in R
Hi!你好!
This is how my plot looks at the moment... Want to try and only display decades 1980 and 2010 in my box plots.这就是我的 plot 现在的样子……想尝试在我的箱线图中只显示 1980 年和 2010 年的几十年。 This is how my code looks now:
这就是我的代码现在的样子:
gender_race_income <- ggplot(data = gender_pay_gap, aes(x = factor(decade), y = income, colour
= sex)) +
geom_boxplot() +
coord_flip() +
facet_grid(rows = vars(race)) +
scale_y_log10() +
theme_bw() +
scale_color_brewer(palette = "Set2")
Thank you:)谢谢:)
welcome to Stack Overflow.欢迎来到堆栈溢出。 You can subset your data using
filter()
from dplyr
and then pass this onto the ggplot using the %>%
pipe.您可以使用来自
dplyr
的filter()
对数据进行子集化,然后使用%>%
pipe 将其传递到 ggplot。
gender_pay_gap %>%
dplyr::filter(decade == 1980 | decade == 2010) %>%
ggplot(aes(x = factor(decade), y = income, colour = sex)) +
geom_boxplot() +
coord_flip() +
facet_grid(rows = vars(race)) +
scale_y_log10() +
theme_bw() +
scale_color_brewer(palette = "Set2")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.