I have loaded a log onto a dataframe v
. You can see the output of head(v)
:开发者_开发百科
user_id page_id timestamp
1 139 1612783 2011-02-22 06:24:40
2 139 1612783 2011-02-22 06:28:40
3 139 1612783 2011-02-22 06:41:01
How can I qplot
the number of page_id
's per day?
- On the x-axis it would be the day (e.g.
2011-02-22
). - On the y-axis it would be the number of
page_id
's for that particular date.
This will work:
v <- data.frame(
timestamp = as.Date(c("2011-02-22", "2011-02-22", "2011-02-23")),
page_id = c(1,2,1))
newdata <- data.frame(time=names(new), count=new)
qplot(time, page, data = newdata)
It is worth reading the ggplot manual, which has plenty of qplot
examples, including times series.
t1 = with(v, table(as.Date(timestamp), page_id))
t2 = apply(t1 > 0, 1, sum)
dates = as.Date(names(t2))
plot(t2 ~ dates) # using plot
qplot(dates, t2, data=data.frame(t2, dates)) # using qplot
You can write this in a more compact form, but this way you can check the values of t1
and t2
.
精彩评论