1

这应该是一个非常简单的问题。我有以下代码,它形成了我想要的情节:

library(reshape)
library(ggplot2)
require(ggplot2)
split1_data<-structure(list(Loci = structure(1:8, .Label = c("Baez", "Blue", 
"C147", "C204", "C21", "C278_PT", "C294", "C316"), class = "factor"), 
    All = c(0.3357, 0.4166, 0.0242, 0.9708, 0.4518, 0.0666, 0, 
    0.5925), X1_only = c(0.4758, 0.3188, 0.1465, 0.3209, 1, 0.0278, 
    0.2065, 0.6187), X78_only = c(0.3379, 0.4102, 0.2134, 0.6807, 
    0.8242, 1, 0.0046, 0.279), X8_removed = c(0.0967, 0.5831, 
    0.058, 0.9268, 0.3518, 0.0629, 0, 0.6229), X8_only = c(0.1169, 
    0.8327, 0.2169, 0.0907, 1, 1, 0.07, 0.486), X7_removed = c(0.2989, 
    0.7268, 0.0087, 0.8874, 0.5853, 0.0568, 0, 0.7622), X7_only = c(1, 
    0.5714, 0.2825, 0.8673, 0.5557, 0.6861, 0.0044, 0.1146), 
    X5_removed = c(1, 0.1453, 0.0176, 0.8428, 0.2277, 0.2563, 
    0, 0.5326), X5_only = c(0.0642, 0.631, 0.5193, 0.979, 0.5348, 
    0.1304, 0.02, 0.0217), X4_removed = c(0.4492, 0.3821, 0.0121, 
    0.9957, 0.5158, 0.0498, 0, 0.718), X4_only = c(0.6485, 0.0709, 
    0.1639, 0.6908, 1, 1, 0.4469, 0.639), X3_removed = c(0.3009, 
    0.3414, 0.02, 0.9935, 0.4216, 0.1273, 0, 0.6406), X3_only = c(1, 
    0.9325, 0.772, 0.5505, 1, 0.2068, 0.0829, 0.17), X2_removed = c(0.6335, 
    0.349, 0.2095, 0.9777, 0.8928, 0.0571, 0, 0.4285), X2_only = c(0.191, 
    0.4397, 0.0403, 0.3606, 0.0089, 1, 0.0033, 0.659), X1_removed = c(0.1653, 
    0.7658, 0.0718, 0.7705, 0.4193, 0.1894, 0, 0.5167)), .Names = c("Loci", 
"All", "X1_only", "X78_only", "X8_removed", "X8_only", "X7_removed", 
"X7_only", "X5_removed", "X5_only", "X4_removed", "X4_only", 
"X3_removed", "X3_only", "X2_removed", "X2_only", "X1_removed"
), row.names = c(NA, 8L), class = "data.frame")

split1_datam<-melt(split1_data,id="Loci")

p1<- ggplot(split1_datam, aes(x =Loci, y = value, color = variable, width=.15)) +  
         scale_fill_grey() + 
         geom_bar(position="dodge")+ 
         geom_hline(yintercept=0.05)+ 
         opts(axis.text.x  = theme_text(angle=90, size=8)) +
         scale_y_discrete(breaks=seq(0,1)) + 
         ylab(NULL)
p1

但是,我希望将情节设为灰度,但似乎无法弄清楚如何做到这一点(注意:上面描述的 scale_fit_grey() 对我不起作用)。有什么建议么?非常感谢!

4

1 回答 1

6

一开始使用ggplot2color通常会让人绊倒的一件事是和之间的区别fill。对于条形、矩形等二维对象,基本上任何填充区域都会color影响边框颜色并fill影响内部颜色。

在您的情节中,您 map ,但incolor = variable没有映射。我想知道你的意思是在里面然后使用.fillaesfill = variableaes()scale_fill_grey

否则,您将使用color = variableand scale_color_grey,但这只会“着色”条形的边框,而不是填充区域。

例如,fill = variablescale_fill_grey()得到这样的结果:

在此处输入图像描述

于 2012-06-18T03:09:40.697 回答