1

I try to create a chart in Python using ggplot library.

My data is in this format:

id total
1  3
1  4
1  7
2  3
2  2
2  5

I want to create a bar chart where every id has it's own bar. The y will be the average of total column for the specific id and also add error area with min and max for each bar.

I am new on ggplot. I have worked with scatter plots and line graph but not with bar chart.

I found that bar charts can be created with

gg = ggplot(mydata, aes(....)) + geom_bar()

But I cannot figure what to add on aes.

4

1 回答 1

0

根据原始 Rggplot2文档(我添加了一些粗体):

条形的高度通常代表两件事之一:每组中的案例计数,或数据框列中的值。默认情况下,geom_bar 使用 stat="bin"。这使得每个条形的高度等于每组中的案例数,并且与将值映射到 y 美学不兼容。如果您希望条形的高度表示数据中的值,请使用 stat="identity" 并将值映射到 y 美学。

这也适用于惊人的 Python 端口:

ggplot(mydata, aes(x='id', y='total')) + geom_bar(stat='identity')

看起来像: 简单的ggplot条形图

在这种情况下,x 刻度显然有点奇怪,但我将把它留给另一个问题!

于 2015-06-17T12:29:25.747 回答