Q:

Visualize ..count.. in a line graph with ggplot2

I have a data frame with tweets (containing a timecode, tweet-id, text, etc.) and want to visualise the amount of tweets per hour. It works fine with a bar graph:

I use the following code to produce the bar graph (created stores the timecode of a tweet in POSIX format):
  ggplot(data=tweets_frame, aes(x=created)) + 
     geom_bar(aes(fill=..count..), binwidth=3600) + 
     scale_x_datetime("Time") + 
     scale_y_continuous("Tweets")

I want to produce the same graph, but as line graph instead of as bar graph.
I tried to just replace geom_bar with geom_line:
  ggplot(data=tweets_frame, aes(x=created)) + 
     geom_line(aes(fill=..count..), binwidth=3600) + 
     scale_x_datetime("Time") + 
     scale_y_continuous("Tweets")

Which resulted in this error message:

Error in eval(expr, envir, enclos) : object 'count' not found

I cannot figure out how to specify the ..count.. in a line graph.

A:

You can switch from stat="identity", the default setting with geom_line,  to stat="bin", which allows the use of ..count...  I used the mtcars data for this example, and I arbitrarily set binwidth to 10.
ggplot(data=mtcars, aes(x=hp)) + geom_line(aes(fill=..count..), stat="bin", binwidth=10).

