[英]Plotting dates versus cumulative character values
I have the following data set called someDat
showing registration date of users: 我有以下数据集someDat
显示用户的注册日期:
dates users
11/06/2013 alfred
12/06/2013 andrew
12/06/2013 john
15/06/2013 jojo
15/06/2013 jeff
15/06/2013 samson
18/06/2013 dave
18/06/2013 hamsa
19/06/2013 kambua
Now I'd like to plot dates versus cumulative number of users, as shown in the image. 现在我想绘制日期与累计用户数,如图所示。 I've tried converting the users
into factors and then use the function cumsum
but its just not giving me the right graph. 我已经尝试将users
转换为因子,然后使用函数cumsum
但它只是没有给我正确的图形。
usersSum <- cumsum(as.numeric(factor(someDat$users))); usersSum
plot(someDat$date,someDat$users, type= "b")
I can't figure out where I'm going wrong or whether its the right function to use. 我无法弄清楚我哪里出错或者它是否正确使用。 Any help will be appreciated. 任何帮助将不胜感激。
someDat <- read.table(text=' dates users
11/06/2013 alfred
12/06/2013 andrew
12/06/2013 john
15/06/2013 jojo
15/06/2013 jeff
15/06/2013 samson
18/06/2013 dave
18/06/2013 hamsa
19/06/2013 kambua',header=TRUE)
someDat$cumsum <- 1:nrow(someDat)
someDat$date2 <- as.POSIXct(as.character(someDat$dates),format='%d/%m/%Y')
# as lines (left plot)
plot(someDat[!duplicated(someDat$dates, fromLast=TRUE),c('date2','cumsum')],type='l')
# as steps (right plot, following DWin)
plot(someDat[!duplicated(someDat$dates, fromLast=TRUE),c('date2','cumsum')],type='l')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.