0

I am having a real hard time with ggplot function!

I try to briefly explain my problem.

I have a dataset of several tweets associated to a time stamp; I would like to plot the data obtaining a graph with time on the x bar and the frequency or the "tweet-rate" per hour on the y axis.

What did I do?

library(ggplot2)
c4l.tweets <- read.csv("/Users/vincenzo/Desktop/Collect %23c4l13 Tweets - Archive.csv")
c4l.tweets$time <- as.POSIXct(strptime(c4l.tweets$time, "%d/%m/%Y %H:%M:%S", tz="CST") -       6*60*60)

library(chron)
c4l.tweets$by.hour <- trunc(c4l.tweets$time, units="hours")


ggplot(count(c4l.tweets, "by.hour"), aes(x=by.hour, y=freq))
+ geom_bar(stat="identity") + xlab("Number") + ylab("Date") + labs(title="tweets   by hour")

So basically I truncated the data by the timestamp and used the count function to plot them.

I get the

 Error: No layers in plot

and

Error in +geom_bar(stat = "identity") : argument not valid for the operator

But why? what am I doing wrong? I usually have this problem each time i try to plot something via ggplot, what do I do wrong?

Thank you! Vincenzo

3
  • 5
    don't break the line before the + ... or put parentheses around the whole expression to stop R interpreting the ggplot() call before you get a chance to add geoms to it. Commented Dec 29, 2013 at 23:42
  • 1
    you are encouraged to post an answer to your own question based on this hint (you may have to wait another hour or so before you're allowed to) Commented Dec 30, 2013 at 0:23
  • there are similar questions: stackoverflow.com/questions/15388748/… but I don't think they're exact duplicates. Commented Dec 30, 2013 at 0:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.