【问题标题】:Why does my graph look like this when I try to plot two variables onto the same plot?当我尝试将两个变量绘制到同一个图上时,为什么我的图看起来像这样?
【发布时间】:2020-02-04 15:21:50
【问题描述】:

您可以使用以下代码创建数据框:

structure(list(year = c(1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969), DAI = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), Severity = c(0, 0, 0, 0, 3, 20, 50, 80, 90, 100, 100, 0, 0, 0, 0, 0, 0, 0, 3, 6, 30, 70)), class = "data.frame", row.names = c(NA, -22L))

我想在一个区域中创建两个图,然后我将使用 pracma 包估计每条曲线下的区域。我用来创建情节的代码是:

  p2 <- ggplot(df4, aes(x=DAI, y=Severity, color=year)) + geom_line()
  p2

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您需要将year 放入factor

    library(ggplot2)
    
    df <- structure(list(year = c(1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1968, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969, 1969), DAI = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), Severity = c(0, 0, 0, 0, 3, 20, 50, 80, 90, 100, 100, 0, 0, 0, 0, 0, 0, 0, 3, 6, 30, 70)), class = "data.frame", row.names = c(NA, -22L))
    
    ggplot(df,aes(x=DAI,y=Severity,color = factor(year)))+geom_line()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 2017-06-17
      • 1970-01-01
      • 2011-04-29
      • 2022-01-04
      相关资源
      最近更新 更多