I have been using a consistent colour scheme across multiple bar plots using data from different data frames that share a common variable. This approach was based on an answer to this question. In each of these cases I was looking at one variable.
What I would like to do now is look at two variables on the same plot keeping the colour scheme consistent. It should look something like the following except the two bars for A
should be the same colour (the first in the palette), the two bars for B
should be the same colour (the second in the palette), etc.
Sample data:
mydata <- data.frame( "Channel" = LETTERS[1:11],
"V1" = seq(1100, 100, -100),
"V2"= seq(110, 10, -10) )
and code for the above plot:
barplot(t(mydata[,2:3]), beside=T,
col=brewer.pal(11, "RdGy"),
names.arg=LETTERS[1:11])
I have been trying to do this in ggplot (which is my preference) but haven't succeeded. I have used the package reshape2
to melt
the data and then use fill
but that only gets me two colours. I have also tried using position='dodge'
in various ways with no luck. I can get to a similar end result combining a bar plot and a line graph for the second variable but would prefer the double bar plot.
I would also prefer to stick with ggplot but any solution would be appreciated.