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

ggplot2で最初に人々をつまずかせるのは、colorとの違いfillです。バー、長方形、基本的に塗りつぶされた領域などの2Dオブジェクトの場合color境界線の色と内部fillの色に影響します。

プロットでは、をマップcolor = variableしますが、のマッピングはありませfillaesfill = variable中を意味してaes()、それから使うつもりだったのかしらscale_fill_grey

それ以外の場合は、とを使用color = variableしますscale_color_greyが、これはバーの境界線を「色付け」するだけで、塗りつぶされた領域は「色付け」しません。

たとえば、fill = variablescale_fill_grey()私は次のようなものを取得します:

ここに画像の説明を入力してください

于 2012-06-18T03:09:40.697 に答える