我想將我的x軸分成兩組。我已經設法使一個小組使用方面,但不能做第二個小組。這裏是我已經擁有的和我想要的東西的圖片。 這裏也是我的命令:R中的ggplot - 將x軸分成兩組
ggplot(myk.p, aes(x=Group, y=Colonization, fill=MO)) +
geom_bar(stat="identity", colour="black") +
scale_fill_manual(values=c("#000000","#7a7a7a","#c0c0c0")) +
theme(panel.margin = unit(0, "lines"), strip.background =
element_blank()) + facet_wrap(~Water, switch = "x", scales = "free_x") +
ggtitle("Root mycorrhization in % (Populus nigra)")
例Data.csv:
"Group" "Colonization" "MO" "Water" "Fertilizer"
"P1" 69,2307692308 "C" "once" "without"
"P2" 71,8232044199 "F" "once" "without"
"P3" 82,5174825175 "I" "once" "without"
"P4" 66,4122137405 "C" "once" "with"
"P5" 86,013986014 "F" "once" "with"
"P6" 98,7654320988 "I" "once" "with"
"P7" 41,9540229885 "C" "twice" "without"
"P8" 65,7894736842 "F" "twice" "without"
"P9" 63,9705882353 "I" "twice" "without"
"P10" 62,5850340136 "C" "twice" "with"
"P11" 87,012987013 "F" "twice" "with"
"P12" 89,696969697 "I" "twice" "with"
如果你願意,你可以做'facet_grid',而不是'facet_wrap',儘管這會給你一個2x2的陰謀 –
你需要包括足夠的數據,使你的問題[reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。一般來說,你需要面對一個有兩個層次的變量來獲得兩個方面。 – alistaire
我添加了一個示例csv文件。 –