Re: [R] background color in scatterplots

From: Mike Prager <mike.prager_at_noaa.gov>
Date: Fri, 28 Mar 2008 17:59:21 -0400

"Georg Ehret" <georgehret_at_gmail.com> wrote:

> Dear R community, I have a scatterplot with multiple vertical ablines. I
> wish to color each interval between two ablines in a different color...
> Could you please indicate me how to do this efficiently?
>
> Thank you!
> Georg.
> ********************

Dear Georg,

Try this example:

# Demonstrate scatterplot w/ different color bands # M.H.P. - March 2008
graphics.off()
# Generate dummy data & make a blank plot: a <- runif(100)
b <- 2 * runif(100)
plot(a, b, type = "n", main = "Demonstration") # Set the values of the x-axis references: vrefs <- c(0.2, 0.4, 0.6)
# Get coordinates of plot
pdims <- par()$usr
# Concatenate them to the vector of x_axis references: vrefs2 <- c(pdims[1], vrefs, pdims[2])
# Generate some weak colors:
cols <- rainbow(n = length(vrefs2), s = 0.15) # Add the colors to the plot:
for (i in 2:length(vrefs2)){

    polygon(c(vrefs2[(i-1):i], vrefs2[i:(i-1)]),

        c(rep(pdims[3],2), rep(pdims[4],2)), col = cols[i],
        border = NA)

    }
# Draw the reference lines, points, and box: abline(v = vrefs)
points(a, b, lwd = 1.5)
box()
-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
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.
Received on Fri 28 Mar 2008 - 22:05:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 29 Mar 2008 - 00:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive