首页 > 解决方案 > 绘图中的重叠线(ggplot2)

问题描述

我需要一些帮助来创建类似图 2 的图。我不知道问题是我的数据还是代码。但正如您在第一个图形中看到的那样,存在重叠,我想要一个更柔和的图形作为第二个图像。另一方面。有人可以订购日期吗?

ggplot(data = consum, mapping = aes(x = Month, y = Cpc, color = Year, group = 1)) +
      geom_line() +
      facet_wrap(~Type) + 
      theme_bw() + 
      scale_color_manual(values = c("orange", "blue"))
```

在此处输入图像描述

structure(list(Month = c("January", "Frebrary", "March", "April", 
"January", "Frebrary", "March", "April", "January", "Frebrary", 
"March", "April", "January", "Frebrary", "March", "April", "May", 
"January", "Frebrary", "March", "April", "January", "Frebrary", 
"March", "April"), Cpc = c(52.6030417616108, 52.3807979985595, 
63.4812345277527, 69.9337994172852, 4.87131485047933, 5.10130976154746, 
5.81295804297682, 6.85707419263629, 7.155082484813, 7.24882986945935, 
8.32846647323954, 9.80847493902699, 6.94921351149698, 6.55179853175549, 
7.35259139659446, 6.95037273611445, 8.03280438298055, 4.60674099035869, 
4.47914291992134, 4.95627076108138, 4.57283076670216, 51.3581426441543, 
47.660340330082, 52.8289135861524, 50.6656566779732), Year = c("2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2019", "2019", "2019", "2019", "2019", 
"2019", "2019", "2019", "2019", "2019", "2019", "2019", "2019"
), Type = c("Total feeding", "Total feeding", "Total feeding", 
"Total feeding", "Fresh vegetables", "Fresh vegetables", "Fresh vegetables", 
"Fresh vegetables", "Fresh fruits", "Fresh fruits", "Fresh fruits", 
"Fresh fruits", "Fresh fruits", "Fresh fruits", "Fresh fruits", 
"Fresh fruits", "Fresh fruits", "Fresh vegetables", "Fresh vegetables", 
"Fresh vegetables", "Fresh vegetables", "Total feeding", "Total feeding", 
"Total feeding", "Total feeding")), row.names = c(NA, -25L), class = c("tbl_df", 
"tbl", "data.frame"))

在此处输入图像描述

标签: rggplot2geom

解决方案


推荐阅读