This should be a pretty straightforward question. I have the following code, which forms the plot I want:
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
However, I was hoping to make the plot greyscale, but can’t seem to figure out how to accomplish this (note: the scale_fit_grey() depicted above is not working for me). Any suggestions? Thanks so much!
One thing that commonly trips people up at the start with ggplot2 is the difference between
colorandfill. For 2D objects like bars, rectangles, basically any filled area,coloraffects the border color andfillaffects the interior color.In your plot, you map
color = variable, but there is no mapping forfillinaes. I wonder if you meantfill = variableinsideaes()and then to usescale_fill_grey.Otherwise, you’d use
color = variableandscale_color_grey, but that would only “color” the borders of the bars, not the filled areas.For instance, with
fill = variableandscale_fill_grey()I get something like this: