[geom_bar和geom_point在同一ggplot中,在同一组中

问题描述 投票:0回答:1

我有当前代码

ggplot(data = niveles[niveles$departamento=="CUNDINAMARCA" &
                        niveles$prueba=="MATEMÁTICAS" &
                        !is.na(niveles$nivel),]) + 
  geom_bar(stat="identity", position = position_dodge(),
           aes(x = año, y = desempeño, fill = nivel)) +
  geom_point(data = niveles[niveles$prueba=="MATEMÁTICAS" &
                              niveles$departamento=="COLOMBIA" &
                              !is.na(niveles$nivel),], shape = 24,
             aes(x = año, y = desempeño, group = nivel, fill = "blue")) 

这给了我下面的情节:

enter image description here

但是,我希望获得每个“点”及其对应的“ niveles”变量类别。有人知道我该怎么做吗?

事先考虑。

r ggplot2 geom-bar
1个回答
0
投票

您可以像使用position=position_dodge()来避开条形一样避开点。但是,您需要添加width参数来指定要减淡多少。值为1时应与闪避的条对应。您在图例中也有一个未知的“蓝色”类别。这是因为fill参数应出现在美学之外[aes

© www.soinside.com 2019 - 2024. All rights reserved.