【发布时间】:2021-12-07 20:13:08
【问题描述】:
如何在省略 NA 的同时绘制同一列中的不同变量?
我正在研究 EA Sports 国际足联球员统计数据集
我写的代码是:
plotageleague <- df %>%
group_by(League) %>%
summarise(age = mean(Age))
options(repr.plot.width = 12, repr.plot.height = 8)
ggplot()+
geom_histogram(df, mapping = aes(Age, fill = League))+
geom_vline(plotageleague, mapping = aes(xintercept = age), color = "red", size = 1.5)+
geom_text(plotageleague, mapping = aes(x = age+3, y = 65, label = round(age,digits = 2)))+
facet_wrap(League~.)+
theme_minimal()+
theme(legend.position = "bottom")+
labs(y = "Frequency", title = "", caption = "")
联赛列包含 12 个不同的足球联赛,每个联赛作为不同的变量和 NA,成为第 13 个图。我不想要那个。我只想要分配了球员的联赛的统计数据(我只将球员分配到实际存在的 30 多个联赛中的 12 个联赛,所以其余球员在“联赛”列中有 NA)
【问题讨论】:
-
filter(!is.na(League))会有所帮助。