我正在处理elo_blatter
数据包中的数据fivethirtyeight
,我想通过population
制作confederation
的箱线图
这是我的代码:
sp <- elo_blatter %>% group_by(conf = confederation) %>% summarise(population = sum(popu06, na.rm = TRUE))
以及箱线图:
mp %>%
group_by(conf) %>%
ggplot()+
geom_boxplot(aes(x=conf, y=population, fill=conf)) +
theme_minimal() +
scale_fill_brewer(palette="Dark2") +
labs(x = "",y = "") +
theme(panel.grid.major.x = element_blank(), legend.position = "none")
看起来像这样
如何解决
如果我使用正常日期,则看起来像enter image description here
问题是当您编码时
... %>% summarise(population = sum(popu06, na.rm = TRUE))
R将返回每个联盟的人口sum,这是单个值。因此,当您绘制箱线图时,它将仅显示线条,因为每个联盟的值仅是其总和。除非每个联盟都拥有一个值的向量,否则我们可以知道中位数,范围等。
我不确定您要显示什么。我认为,如果不使用箱线图,最好使用barplot比较不同联盟之间的人口。