您可以使用以下代码创建数据框:
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
答案 0 :(得分:2)
您需要将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()