[英]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. 我有一个带有推文的数据框(包含时间码,推文ID,文本等),并希望可视化每小时的推文数量。 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): 我使用以下代码生成条形图(
created
以POSIX格式存储推文的时间代码):
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
: 我想只需更换
geom_bar
与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
eval(expr,envir,enclos)中的错误:找不到对象'count'
I cannot figure out how to specify the ..count..
in a line graph. 我无法弄清楚如何在折线图中指定
..count..
You can switch from stat="identity"
, the default setting with geom_line
, to stat="bin"
, which allows the use of ..count..
. 您可以从
stat="identity"
(使用geom_line
的默认设置) geom_line
到stat="bin"
,这允许使用..count..
I used the mtcars
data for this example, and I arbitrarily set binwidth
to 10. 我在这个例子中使用了
mtcars
数据,我随意将binwidth
设置为10。
ggplot(data=mtcars, aes(x=hp)) + geom_line(aes(fill=..count..), stat="bin", binwidth=10).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.