I'm dealing with a data-frame in R that looks like this
test <- data.frame(c(1:4),c(5:8),c(9:12),c(13:16))
names(test) <- c("position","totalA","totalB","totalC")
No I want to create a stacked barplot, where all bars are in black, except for 1 value of position, there I want different colors for 'totalA', 'totalB' and 'totalC'
This is what I did to create the barplot
test.melt <- melt(test, id = "position")
ggplot(test.melt, aes(x=position, y=value, fill=variable))+geom_bar(stat="identity")+scale_fill_manual(values=grey.colors(3))
so now all bars are conditionally colored, but this should only be the case when position == 2. For the rest all bars should be black.
EDIT: I need to do this also while just using the barplot() function instead of ggplot().
I use this for the barplot
test.transposed <- setNames(data.frame(t(test[,-1])), test [,1])
barplot(as.matrix(test.transposed))
But again, how can I now apply this conditional coloring ?