2010-09-07 172 views
3

我有两组数据(3列:x = categorical,y =数字,l =位置),我想创建一个条形图,其中包含x轴上的类别,对于每个类别的值,垂直条,颜色不同,每个位置的y值。默认情况下,Excel/OpenOffice生成这种图表。如何用ggplot创建并排的条形图(用于多个系列)?

我试图

qplot (x,y,data=mydata,col=location, geom="histogram") 

但它产生堆积条形图,不并排。然后我查看了ggplot2文档,没有找到任何其他可以使用的geom(见下面的完整列表)。

这不可能与ggplot2?

在此先感谢。

Name Description 
abline - Line, specified by slope and intercept 
area - Area plots 
bar - Bars, rectangles with bases on y-axis 
blank - Blank, draws nothing 
boxplot - Box-and-whisker plot 
contour - Display contours of a 3d surface in 2d 
crossbar - Hollow bar with middle indicated by horizontal line 
density - Display a smooth density estimate 
density_2d - Contours from a 2d density estimate 
errorbar - Error bars 
histogram - Histogram 
hline - Line, horizontal 
interval - Base for all interval (range) geoms 
jitter - Points, jittered to reduce overplotting 
line - Connect observations, in order of x value 
linerange - An interval represented by a vertical line 
path - Connect observations, in original order 
point - Points, as for a scatterplot 
pointrange - An interval represented by a vertical line, with a point 
in the middle 
polygon - Polygon, a filled path 
quantile - Add quantile lines from a quantile regression 
ribbon - Ribbons, y range with continuous x values 
rug - Marginal rug plots 
segment - Single line segments 
smooth - Add a smoothed condition mean 
step - Connect observations by stairs 
text - Textual annotations 
tile - Tile plot as densely as possible, assuming that every tile is the same size 
vline - Line, vertical 
+1

几何对象,而不是几何对象。 – hadley 2010-09-07 23:08:16

+0

我已经纠正了这个问题。并感谢您创建ggplot2! – wishihadabettername 2010-09-08 00:33:19

回答

2

有一个position参数默认为stack这里。使用:

qplot (x,y,data=mydata,col=location, geom="bar", position="dodge") 

这是在手册中,只需搜索“闪避”。另外,如果y值给出了条的高度,则可能需要“条”几何。

相关问题