在geom_freqpoly行下填充区域的最简单方法是什么? [英] What is the simplest method to fill the area under a geom_freqpoly line?

查看:1249
本文介绍了在geom_freqpoly行下填充区域的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x轴是时间间隔的时间分解。数据框中有一个间隔列,用于指定每行的时间。该列是一个因素,其中每个区间是一个不同的因素级别。



使用geom_histogram和geom_freqpoly绘制直方图或线条效果很好,但我希望有一个line,就像geom_freqpoly提供的那样,填充区域。



目前我使用的是geom_freqpoly,像这样:

  ggplot(quake.data,aes(interval,fill = tweet.type))+ geom_freqpoly(aes(group = tweet.type,color = tweet.type))+ opts(axis .text.x = theme_text(angle = -60,hjust = 0,size = 6))



我宁愿有一个填充区域,例如由 geom_density 提供,但不会平滑该行: $ b



geom_area 已建议,有没有办法使用ggplot2生成的统计信息,如..count ..,用于geom_area的y-值?或者,在使用ggplot2之前是否需要进行计数聚合?




正如答案中所述,geom_area(..

  ggplot(quake.data,aes(interval))+ geom_area(()。,stat =bin)是解决方案: aes(y = ..count ..,fill = tweet.type,group = tweet.type),stat =bin)+ opts(axis.text.x = theme_text(angle = -60,hjust = 0,size = 6))

产生:

解决方案

也许你想要:

$ $ $ $ $ $ $ $ $ $ geom_area(aes(y = ..count ..),stat =bin)


The x-axis is time broken up into time intervals. There is an interval column in the data frame that specifies the time for each row. The column is a factor, where each interval is a different factor level.

Plotting a histogram or line using geom_histogram and geom_freqpoly works great, but I'd like to have a line, like that provided by geom_freqpoly, with the area filled.

Currently I'm using geom_freqpoly like this:

ggplot(quake.data, aes(interval, fill=tweet.type)) + geom_freqpoly(aes(group = tweet.type, colour = tweet.type)) + opts(axis.text.x=theme_text(angle=-60, hjust=0, size = 6))

I would prefer to have a filled area, such as provided by geom_density, but without smoothing the line:

The geom_area has been suggested, is there any way to use a ggplot2-generated statistic, such as ..count.., for the geom_area's y-values? Or, does the count aggregation need to occur prior to using ggplot2?


As stated in the answer, geom_area(..., stat = "bin") is the solution:

ggplot(quake.data, aes(interval)) + geom_area(aes(y = ..count.., fill = tweet.type, group = tweet.type), stat = "bin") + opts(axis.text.x=theme_text(angle=-60, hjust=0, size = 6))

produces:

解决方案

Perhaps you want:

geom_area(aes(y = ..count..), stat = "bin")

这篇关于在geom_freqpoly行下填充区域的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆