R 编程:创建堆叠条形图,每个堆叠条形具有可变颜色
我正在尝试创建一个堆叠条形图,每个堆叠条形图中的颜色可变;也就是说,一个条形图在红色上方显示蓝色,下一个条形图在紫色上方显示红色,等等。我还想保留堆叠图表的功能。非常感谢你们。
亚当
I'm trying to create a stacked bar graph with variable coloring in each stacked bar; that is, one bar has say blue on top of red, the next one red on top of purple, etc. I also wanted to preserve the ability to stack graphs. Thank you so much guys.
Adam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下图(使用上面的代码创建)显示了主要汽车制造商生产的汽车类型。
我将条形高度(实际上是条形段高度)映射到汽车类别;我将条形段颜色映射到汽车制造商。因此,七个 x 轴标签中的每一个都对应于因子“类”中的一个级别;同样,条形段的每种颜色对应于因素“制造商”中的一个级别(“制造商”和“类别”都是“mpg”数据框中的变量/列。最后,y 轴显示汽车数量在每个类别(条形高度)中按制造商(段颜色)
alt text http:// img245.imageshack.us/img245/6678/stackedbar.png
The plot below (which was created w/ the code just above it) shows the type of cars produced by the major car makers.
I mapped bar height (actually bar-segment height) to automobile class; and I mapped bar-segment color to automobile manufacturer. Hence, each of the seven x-axis labels corresponds to one level in the factor 'class'; likewise, each color of the bar segments corresponds to one level in the factor 'manufacturer' (both 'manufacturer' and 'class' are variables/columns w/in the 'mpg' dataframe. Finally, the y axis shows the number of cars in each class (bar height) by manufacturer (segment color).
alt text http://img245.imageshack.us/img245/6678/stackedbar.png