R叠线图不想显示最后一个变量(ggplot)[关闭]

问题描述 投票:-3回答:1

我制作了漂亮的堆积线图,但是最后一个变量(蓝色)不想显示(2019年)。

stacked line graph

df_plot具有三个变量:

  • 数字变量:“年份”
  • 因子变量“组”
  • 整数变量:“ Count”

这是我的代码:

ggplot(data = df_plot)  + 
      geom_area(aes(x = Year, y=Count, fill = Group)) +
      scale_y_continuous() +
      theme_economist() +
      labs( x = "Year",
           y = "Count",
           caption = "source") +
      theme(legend.title = element_blank(), legend.text = element_blank()) +
      theme(plot.title = element_text(size=13)) + 
      theme(plot.subtitle = element_text(size=12)) + 
      scale_fill_brewer(palette = "Spectral") 

UPD我发现了问题。这是由于我没有为那年未发生的组提供计数0的行。

r ggplot2 grouping stacked-chart linegraph
1个回答
0
投票

我发现了我的问题。这是由于我没有为那年未发生的组提供计数0的行。

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