Как создать параллельные гистограммы (для нескольких серий) с помощью ggplot? - PullRequest
5 голосов
/ 07 сентября 2010

У меня есть два набора данных (3 столбца: x = категориальный, y = числовой, l = местоположение), и я хотел бы создать гистограмму с категориями на оси x и для каждого значения категории: две вертикальные полосы, окрашенные по-разному, со значениями y для каждого местоположения. По умолчанию Excel / OpenOffice создает диаграммы такого типа.

Я пытался

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 Ответ

3 голосов
/ 07 сентября 2010

Здесь есть аргумент position, который по умолчанию равен stack. Использование:

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

Это в руководстве, просто поиск "dodge". Кроме того, вы, вероятно, захотите geom "bar", если значения y дают высоту бара.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...