R ggplot几何图形光面减淡

R ggplot几何图形光面减淡,r,ggplot2,R,Ggplot2,在ggplot2中生成平面条形图时遇到一些问题。也许这是很明显的事情,但我无法理解:(我有以下数据集: structure(list(COUNTRY = structure(c(1L, 4L, 7L, 10L, 13L, 16L, 19L, 2L, 5L, 8L, 11L, 14L, 17L, 20L, 3L, 6L, 9L, 12L, 15L, 18L, 2L, 5L, 8L, 11L, 14L, 17L, 20L, 3L, 6L, 9L, 12L, 15L, 18L, 1L, 4L,

在ggplot2中生成平面条形图时遇到一些问题。也许这是很明显的事情,但我无法理解:(我有以下数据集:

structure(list(COUNTRY = structure(c(1L, 4L, 7L, 10L, 13L, 16L, 
19L, 2L, 5L, 8L, 11L, 14L, 17L, 20L, 3L, 6L, 9L, 12L, 15L, 18L, 
2L, 5L, 8L, 11L, 14L, 17L, 20L, 3L, 6L, 9L, 12L, 15L, 18L, 1L, 
4L, 7L, 10L, 13L, 16L, 19L, 3L, 6L, 9L, 12L, 15L, 18L, 1L, 4L, 
7L, 10L, 13L, 16L, 19L, 2L, 5L, 8L, 11L, 14L, 17L, 20L), .Label = c("Angola", 
"Botswana", "Burundi", "Comoros", "Eritrea", "Ethiopia", "Kenya", 
"Lesotho", "Madagascar", "Malawi", "Mozambique", "Namibia", "Rwanda", 
"Somalia", "South Africa", "Swaziland", "Tanzania", "Uganda", 
"Zambia", "Zimbabwe"), class = "factor"), Year = structure(c(2L, 
2L, 14L, 16L, 16L, 11L, 12L, 2L, 4L, 15L, 5L, 10L, 16L, 16L, 
2L, 17L, 14L, 11L, 12L, 10L, 2L, 4L, 15L, 5L, 10L, 16L, 16L, 
2L, 17L, 14L, 11L, 12L, 10L, 2L, 2L, 14L, 16L, 16L, 11L, 12L, 
2L, 17L, 14L, 11L, 12L, 10L, 2L, 2L, 14L, 16L, 16L, 11L, 12L, 
2L, 4L, 15L, 5L, 10L, 16L, 16L), .Label = c("1998", "2000", "2001/2", 
"2002", "2003", "2003/4", "2004", "2005", "2005/6", "2006", "2006/7", 
"2007", "2007/8", "2008/9", "2009", "2010", "2011"), class = "factor"), 
    sex = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L), .Label = c("m", "f", "b"), class = "factor"), 
    location = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Urban", "Rural", "Total", 
    "Capital.City", "Other.Cities.towns", "Urban.Non.slum", "Urban.Slum"
    ), class = "factor"), percent = c(60.4, 42.3, 85.4919452426806, 
    96.3, 90.2847535659154, 87.7347421555771, 87.7323067592087, 
    80.4, 80.6, 93.8186266493188, 75.0109418832216, 36.8, 87.1059275774722, 
    90.1216932603937, 66.8, 83.6279398931798, 89.690685909038, 
    88.8207941092749, 94.6139558774441, 88.0251085200726, 70.4, 
    54.7, 86.1919805548309, 56.9792710715853, 13.1, 75.6355555697382, 
    86.8196674671991, 42.5, 61.9452522893308, 77.597285694676, 
    88.3453320625631, 94.5192341778471, 80.6271302923487, 44.1, 
    29, 77.8542469357068, 90, 86.7073851186482, 83.8921034867784, 
    76.4094871587916, 49.3, 63.952805392032, 77.004884485532, 
    88.6723566877386, 93.9560433940531, 82.3095948307742, 56.1, 
    31.1, 80.0235653889704, 91.5, 88.3809682134183, 85.5656196766576, 
    80.0539027063387, 77, 61.2, 89.2538966046165, 59.6756344409838, 
    23, 79.6749544074645, 86.9507859695728)), .Names = c("COUNTRY", 
"Year", "sex", "location", "percent"), row.names = c(1L, 4L, 
7L, 10L, 13L, 16L, 19L, 22L, 25L, 28L, 31L, 34L, 37L, 40L, 43L, 
46L, 49L, 52L, 55L, 58L, 62L, 65L, 68L, 71L, 74L, 77L, 80L, 83L, 
86L, 89L, 92L, 95L, 98L, 101L, 104L, 107L, 110L, 113L, 116L, 
119L, 123L, 126L, 129L, 132L, 135L, 138L, 141L, 144L, 147L, 150L, 
153L, 156L, 159L, 162L, 165L, 168L, 171L, 174L, 177L, 180L), class = "data.frame")
我正在尝试绘制一个bar_图,该图显示了许多国家的农村、城市地区(以及平均值)人口的百分比,并希望显示按性别划分的比例。我可以使用ggplot函数中的子集调用,在一个简单的条形图上绘制其中一个类别,如下所示:

ggplot(edu_melt[c(edu_melt$sex!="b" & edu_melt$location==c("Urban")), ], aes(x=COUNTRY, y=percent, fill=sex)) + geom_bar(position="dodge", width=0.5) + facet_grid(~location) + labs(x="Country") + theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1))
然而,我想比较整个位置的数据(例如城市、农村和两者).我以为这是一个简单的引入facet_wrap调用的例子,但是我得到一些奇怪的行为,数据在三个facet上绘制-我希望每个facet上有20对条,但是这个代码在三个facet上产生20对条

ggplot(edu_melt_over[c(edu_melt_over$sex!="b"),], aes(x=COUNTRY, y=percent, fill=sex)) + geom_bar(position="dodge", width=0.5, space=1) + facet_wrap(~location, nrow=3) + labs(x="Country", title="Proportion Net Primary School Enrolement in ESA") + theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1))
我不知道为什么会发生这种情况,但我已经寻找了一些提示和技巧,并尝试了许多方法,但得到了相同的结果。有人知道我如何制作这个情节吗

谢谢


Marty

你的数据看起来很奇怪,因为你似乎没有在同一阶层中有任何男女组合(例如,安哥拉有男性城市百分比,但没有女性)。这是数据,而不是绘图

ggplot(edu_melt[edu_melt$sex!="b", ], aes(x=COUNTRY, y=percent, fill=sex)) +
geom_bar(position="dodge", width=0.25) + facet_grid(location~.) + labs(x="Country") +
theme(axis.text.x = element_text(angle=30))

数据集名为
edu\u melt
?另外,
edu\u melt\u over
来自何处?--请为绘图提供图像,如果您没有足够的声誉,请删除图像定义中的前导
,然后有人可以编辑。感谢您的快速响应。我现在已经弄清楚了,我有了自己的子集ginal dataframe和调用错误,因此只选择了部分数据。现在已修复!!抱歉:)