【问题标题】:How to compare years in ggplot2 R如何比较ggplot2 R中的年份
【发布时间】:2020-06-05 07:04:38
【问题描述】:

如何将 2 年与 R 中的 ggplot2 进行比较?

我有一个数据集,如下所示:

month: num 2 4 6 8 10 11 12 1
year:  factor 2018 2019 2018 2019
value: num 1000 11555 111220 14445 

我需要在一个情节中比较这 2 年的几个月。
我的 x 轴需要是月
我的 y 轴必须是值
我的线条需要是年份值。

【问题讨论】:

  • 到目前为止您尝试过什么?为什么它不能满足您的需求?
  • 欢迎来到 Stack Overflow!您能否通过共享您的数据样本来重现您的问题,以便其他人可以提供帮助(请不要使用str()head() 或屏幕截图)?您可以使用 reprexdatapasta 包来帮助您。另见Help me Help you & How to make a great R reproducible example?

标签: r


【解决方案1】:

我试图以一种有形的方式重现您的数据。这不是您数据的准确表示,因为不清楚实际数据框的样子

    month<- c(2,4,6,8,10,11,12,1)
year<-  c(2018,2019,2018,2019)
value<- c(1000,11555,111220,14445)
x <- data.frame("month" = month, "year" = year, "value" = value)

ggplot(data = x, aes(x = month, y = value, group =1))+
  geom_line()+
  geom_point()

【讨论】:

    猜你喜欢
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多