I am a newbie with a question on color for stacked barplot. Let me preface this by saying I have searched for answers before asking this question, but I'm so new to R plotting that I may not be using the correct search query.
Now, I have a matrix that I would like to plot with a stacked barplot using positive and negative values. I've been able to do this (with some help), but I can't seem to get the bars to accept different colors for positive and negative values. Below is what I've written:
dataset<-as.matrix(read.csv("skin_2hr.csv", header=T, row.names=1))
colors <-c("139", "orange", "132","purple","navy","forestgreen")
barcenter<-barplot(t(dataset[,3:2]), density=c(10,40,20,40,20,40),
main="Skin 2hr Post Exposure",
xlab=expression(paste("kJ/m"^"2",4100K FL")), ylab="number of genes",
names.arg=rownames(dataset),
ylim=c(-150,500), col=colors)
lines(barcenter,dataset[,1])
box()
legend("topleft", legend=rownames(dataset), col=colors,
pch=15, bty="n")
For some reason, the bars are all colored orange.barplot
The data matrix is below:
Total UP DOWN
1 113 92 -21
2 216 130 -86
4 406 266 -140
8 183 136 -47
16 150 119 -31
32 178 144 -34
Is it possible to have barplot color positive values different from negative values in a stacked barplot? If so, could you please offer suggestions as how to do so?
dput(dataset)of your data? Or if very large adput()ofhead(dataset, 20)- P1storius