Bars, rectangles with bases on x-axis
Usage
geom_bar(mapping = NULL, data = NULL, stat = "bin", position = "stack", ...)
Arguments
- mapping
- The aesthetic mapping, usually constructed with
aes
oraes_string
. Only needs to be set at the layer level if you are overriding the plot defaults. - data
- A layer specific dataset - only needed if you want to override the plot defaults.
- stat
- The statistical transformation to use on the data for this layer.
- position
- The position adjustment to use for overlappling points on this layer
- ...
- other arguments passed on to
layer
. This can include aesthetics whose values you want to set, not map. Seelayer
for more details.
Description
The bar geom is used to produce 1d area plots: bar charts for categorical x, and histograms for continuous y. stat_bin explains the details of these summaries in more detail. In particular, you can use the weight
aesthetic to create weighted histograms and barcharts where the height of the bar no longer represent a count of observations, but a sum over some other variable. See the examples for a practical example.
Details
The heights of the bars commonly represent one of two things: either a count of cases in each group, or the values in a column of the data frame. By default, geom_bar
uses stat="bin"
. This makes the height of each bar equal to the number of cases in each group, and it is incompatible with mapping values to the y
aesthetic. If you want the heights of the bars to represent values in the data, use stat="identity"
and map a value to the y
aesthetic.
By default, multiple x's occuring in the same place will be stacked a top one another by position_stack. If you want them to be dodged from side-to-side, see position_dodge
. Finally, position_fill
shows relative propotions at each x by stacking the bars and then stretching or squashing to the same height.
Sometimes, bar charts are used not as a distributional summary, but instead of a dotplot. Generally, it's preferable to use a dotplot (see geom_point
) as it has a better data-ink ratio. However, if you do want to create this type of plot, you can set y to the value you have calculated, and use stat='identity'
A bar chart maps the height of the bar to a variable, and so the base of the bar must always been shown to produce a valid visual comparison. Naomi Robbins has a nice article on this topic. This is the reason it doesn't make sense to use a log-scaled y axis with a bar chart
Aesthetics
geom_bar
understands the following aesthetics (required aesthetics are in bold):
x
alpha
colour
fill
linetype
size
weight
Examples
最新文章
- 企业app分发
- WPF开发经验
- yum -y upgrade 和 yum -y update 区别
- NOIP模拟赛-旅行者问题 解题报告
- Hadoop2.2 federnation联盟的搭建
- Windows下安装GnuRadio最简单的方法(没有之一)
- jQuery 滑动方法slideDown向下滑动元素
- commons-logging log4j的联系区别
- 解析Function.prototype.bind
- SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND <;0.5MB MODEL SIZE
- angular : ngModel 内部流程
- Win7系统默认的壁纸路径
- Dynamics 365 Online-60000 API Limits
- 强化学习(三)用动态规划(DP)求解
- Excel 转为 MySQL 语句
- 实现全选、全不选功能 JQuery
- PyCharm 和 IntelliJ IDEA的破解激活
- Software-Defined Networking:A Comprehensive Survey--Day3
- Linux环境下解压rar文件
- PHP基础记录
热门文章
- Python练习笔记——字符串反转
- AR_销售订单收款基本操作(流程)
- 一个进程发起多个连接和gethostbyname等函数
- USB协议及认知
- WinForm窗体键盘事件,支持方向键和回车键
- Math.Celing、Math.Floor、Math.DivRem与Math.BigMul
- Tree通用的系列方法列表-treepanel
- 程序员Git代码托管平台
- 重温java中的String,StringBuffer,StringBuilder类
- Qt Quick + OpenGL + Bullet初次測试