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.

## Aesthetics

geom_bar understands the following aesthetics (required aesthetics are in bold):

• `x`
• `alpha`
• `colour`
• `fill`
• `linetype`
• `size`
• `weight`
• ## Grouping Bars Together

代码解释
aes中fill可指定不同类显示柱子颜色.
geom_bar()的fill修改柱子填充颜色，color修改柱子外围颜色.
theme()控制图例.
labs()添加x，y轴和主题标签.

## 在柱状图中使用不同颜色—把适当的变量映射到Fill中

代码解释
reorder函数，把柱状图按照大小排列.
xlab()对x轴修改坐标轴注释.
其方法随可以为不同柱子fill不同颜色，但所填充颜色是ggplot2系统自动生成，有时候颜色不好看想要修改为你自己制定的颜色，方法如下：
方法1:breaks()

With this color scheme, the points that fall inside the boxplot are not visible (since they are the same color as the boxplot’s fill). Perhaps leaving the boxplot hollow and drawing its lines in the color would be better.

代码解释
操作自己数据时可能会出现报错 “Continuous value supplied to discrete scale” ，Brian Diggs大神给出的解释是：
Age is a continuous variable, but you are trying to use it in a discrete scale (by specifying the color for specific values of age). In general, a scale maps the variable to the visual; for a continuous age, there is a corresponding color for every possible value of age, not just the ones that happen to appear in your data. However, you can simultaneously treat age as a categorical variable (factor) for some of the aesthetics. For the third part of your question, within the scale description, you can define specific labels corresponding to specific breaks in the scale.
也就是要转换连续型变量为因子变量.
方法2：Change the default palettes
These are color-blind-friendly palettes, one with gray, and one with black.

To use with ggplot2, it is possible to store the palette in a variable, then use it later.

## Coloring Negative and Postive Bars Differently—设定新的变量，将新建变量映射到fill中

代码解释
首先通过subset()函数选取一个数集赋值到csub，选取原则为：climate数据中Source这一列值为Berkeley并且Year这一列>= 1900.
csub\$pos为原数集添加pos这一列，若Anomaly10y >= 0则其值为TRUE,否则为FALSE.

最后将pos映射到fill，geom_bar()中size改变柱子外框黑线的厚度.
scale_fill_manual()进行修改颜色，通过设定guide=FALSE 去掉图例.
geom_bar(width=0.5)调整width改变柱子宽度，也就是改变了柱子之间的距离.

## Making a Propotional Stacked Bar Graph

plyr里ddply的语法解析
cabbage是数据集
“Date” 通俗来说就是x轴的变量
transform是要做的变形，在ddply中还有summarize等
最后一项是是新建的变量和变型方法

## 柱条上添加文字

代码解释
ggthemes为ggplot2的一个主题包，通过theme_pander()修改ggplot2默认主题（theme）.

另一种改变柱子顺序方式：

Contribution from ：http://yangchao.me/2013/02/ggplot2-bar-chart/
http://www.bubuko.com/infodetail-1051940.html