[英]Plotting dates versus cumulative character values
我有以下數據集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
現在我想繪制日期與累計用戶數,如圖所示。 我已經嘗試將users
轉換為因子,然后使用函數cumsum
但它只是沒有給我正確的圖形。
usersSum <- cumsum(as.numeric(factor(someDat$users))); usersSum
plot(someDat$date,someDat$users, type= "b")
我無法弄清楚我哪里出錯或者它是否正確使用。 任何幫助將不勝感激。
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.