这里是让你最想要什么样的解决方案。 但请注意,ggplot没有被设计成允许独立“荫”和在一个单一的阴谋“颜色”参数。 相反,我有阴影的obs
和proc
用灰色填充颜色类别,我已经分组的物种进入面(而不是不同的着色他们)。
library(ggplot2)
library(reshape2)
ss.data = data.frame(
pop=c("E1", "E2", "E3", "E4", "E5", "E6", "E7", "C1", "C2", "C3", "C4"),
obs=c(0.0027, 0.0018, 0.0464, 0.0095, 0.0034, 0.0117, 0.017, 0.1178,
0.0449, 0.039, 0.0903),
proc=c(0.0319, 0.0196, 0.0511, 0.0143, 0.0048, 0.0078, 0.0396, 0.1662,
0.074, 0.1681, 0.1358), stringsAsFactors=FALSE)
# Add new column 'species' by removing the trailing digits from 'pop'.
ss.data$species = gsub("\\d", "", ss.data$pop)
# Convert data to long-form with 'melt' from the reshape2 package.
mdat = melt(ss.data, id.vars=c("pop", "species"),
measure.vars=c("obs", "proc"))
plot_1 = ggplot(mdat, aes(x=pop, y=value, fill=variable)) +
theme_bw() +
geom_bar(position="stack", stat="identity") +
scale_fill_manual(values=c("grey50", "grey80")) +
facet_grid(. ~ species, space="free_x", scales="free_x",
labeller=label_both)
ggsave("plot_1.png", plot=plot_1, width=6.5, height=4)