maria at meteo.mcgill.ca
2008-Jun-16 19:15 UTC
[R] barplot with color coding according to value
Hello, I want to use R to produce nice meteograms... For this I would need to color-code my barplot according to the value plotted say if value x > 30 ... the bar is red ; if x between 20 and 10, the bar is blue etc... any ideas how to proceed ? Thank You a lot, maria
Henrique Dallazuanna
2008-Jun-16 19:27 UTC
[R] barplot with color coding according to value
Perhaps something like this:
x <- sample(10:50, 10, rep=TRUE)
cols <- as.character(cut(x,
breaks = c(0, 10, 20, 30,max(x)),
labels = c("green",
"blue", "yellow",
"red")))
barplot(x, col = cols)
On Mon, Jun 16, 2008 at 4:15 PM, <maria@meteo.mcgill.ca> wrote:
> Hello,
>
> I want to use R to produce nice meteograms...
>
> For this I would need to color-code my barplot according to the value
> plotted
>
> say if value x > 30 ... the bar is red ; if x between 20 and 10, the bar
> is blue etc...
>
> any ideas how to proceed ?
>
> Thank You a lot,
> maria
>
> ______________________________________________
> R-help@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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
maria at meteo.mcgill.ca wrote:> Hello, > > I want to use R to produce nice meteograms... > > For this I would need to color-code my barplot according to the value plotted > > say if value x > 30 ... the bar is red ; if x between 20 and 10, the bar > is blue etc... > > any ideas how to proceed ? >Hi Maria, Have a look at "barp" in the plotrix package. Jim