[R] How to change color of bar based on y value of y axis?

Petr PIKAL petr.pikal at precheza.cz
Wed Apr 18 07:09:20 CEST 2012


Hi

> 
> Hi, 
> 
> 
> I m working on bar chart. 
> 
> *Input file:*
> index   -5   1
> index   -4   3
> index   -3   2
> index   -2   10
> index   -1   7
> index   0   2
> index   1   1
> 
> barplot(t(as.matrix(i[3])), ylab= "value", main = "testdata", 
beside=TRUE,
> 
col=c("burlywood1"),horiz=TRUE,cex.names=0.8,names.arg=t(as.matrix(i[,2])))

You still failing to provide reproducible examples.

Maybe you want this.

x<-sample(1:10, 5)
barplot(x, col=c("burlywood1"))
set.seed(333)
y<-sample(-3:0, 5, replace=T)
barplot(x, col=c("burlywood1", "red")[(y==-3)+1])

Regards
Petr

> 
> But i need to change the color of bar where value of  y = -3 
dynamically.
> How can i implement it. 
> 
> Regards http://r.789695.n4.nabble.com/file/n4566636/Screenshot.png 
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/How-to-change-
> color-of-bar-based-on-y-value-of-y-axis-tp4566636p4566636.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list