Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用已汇总的数据在ggplot2上生成条形图_R_Ggplot2 - Fatal编程技术网

R 使用已汇总的数据在ggplot2上生成条形图

R 使用已汇总的数据在ggplot2上生成条形图,r,ggplot2,R,Ggplot2,可能重复: 关于ggplot2参考手册 我们可以看到,使用提供的菱形数据,堆叠条形图非常容易 然而,我尝试使用的数据集与钻石数据不同,因为我的数据已经汇总 附件是我的意思的一个最小的例子 AgeGroup gender Level.of.Education status count 1 18-25 male High School married 10 2 18-25 male High School single 2

可能重复:

关于ggplot2参考手册

我们可以看到,使用提供的菱形数据,堆叠条形图非常容易

然而,我尝试使用的数据集与钻石数据不同,因为我的数据已经汇总

附件是我的意思的一个最小的例子

   AgeGroup gender Level.of.Education  status count
1     18-25   male        High School married    10
2     18-25   male        High School  single    20
3     18-25   male            College married    25
4     18-25   male            College  single    10
5     18-25   male                PhD married    50
6     18-25   male                PhD  single     4
7     18-25   male                GED married    20
8     18-25   male                GED  single   100
9     18-25 female        High School married    20
10    18-25 female        High School  single    10
11    18-25 female            College married    30
12    18-25 female            College  single    60
13    18-25 female                PhD married    80
14    18-25 female                PhD  single    10
15    18-25 female                GED married     5
16    18-25 female                GED  single     2
完整的数据集也有时间框架,所以我想制作一个堆叠的条形图,显示已婚和未婚人士加班的数量,在条形图上填充“教育水平”

完整数据集非常大,因此非常需要这样的聚合数据


你的意见对我有很大帮助。谢谢。

您需要
stat='identity'

ggplot(dat, aes(x=status, y=count, fill=Level.of.Education)) +
    geom_bar(stat='identity')
我还建议按性别分面:

ggplot(dat, aes(x=status, y=count, fill=Level.of.Education)) +
    geom_bar(stat='identity') +
    facet_wrap(~gender)

您需要
stat='identity'

ggplot(dat, aes(x=status, y=count, fill=Level.of.Education)) +
    geom_bar(stat='identity')
我还建议按性别分面:

ggplot(dat, aes(x=status, y=count, fill=Level.of.Education)) +
    geom_bar(stat='identity') +
    facet_wrap(~gender)