使用以下数据我需要绘制因子“in”和“out。”的累积曲线。
years <- c(1969, 1972, 1974, 1975, 1975, 1976, 1976, 1977, 1978, 1978, 1979, 1979, 1980, 1981, 1981, 1982, 1983, 1983, 1984, 1984, 1985, 1985, 1986, 1986, 1987, 1987, 1988, 1988, 1989, 1989, 1990, 1990, 1991, 1991, 1992)
places <- c("in","out","out","in","out","in","out","out","in","out","in", "out","out","in","out","out","in","out","in","out","in","out","in", "out","in","out","in","out","in","out","in","out","in","out","in")
count <- c(1,2,1,1,4,1,1,1,1,1,1,3,3,1,7,4,4,5,1,3,5,3,4,6,7,3,2,6,4,3,6,11,5, 7,9)
peryear <- data.frame(years,places,count)
如果我使用
绘图ggplot(peryear %>% filter(places=="in"),aes(x=years,y=cumsum(count))) + geom_point()+geom_line()
ggplot(peryear %>% filter(places=="out"),aes(x=years,y=cumsum(count))) + geom_point()+geom_line()
我得到了我的期望:
但是,当我尝试将ggplot2与
一起使用时ggplot(peryear,aes(x=years,y=cumsum(count),color=places)) + geom_line()+geom_point()
我得到了以下错误的情节:
我认为这个情节是错误的,因为两个地方的曲线都达到了高于100的值,而对于单个地块,它们达到了70左右。
如何使用ggplot2绘制数据的cumsum曲线?
答案 0 :(得分:2)