Re: [R] diagonally fill a rectangle with color gradient

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 09 Apr 2008 12:57:09 -0600

Here are a couple of ways using base graphics:

> library(TeachingDemos)
> x <- y <- seq(0,1,length.out=100)
> tmp <- expand.grid(x=x,y=y)
> z <- matrix( tmp$x + tmp$y, 100 )
>
> plot( 0:1, 0:1, type='n', xlab='x', ylab='y' )
> subplot( image(x,y,z, col=topo.colors(100), axes=FALSE, xlab='',
ylab=''),
+ c(0.2,0.4), c(0.2,0.7) )
>
> clipplot( image(x,y,z, col=topo.colors(100), add=TRUE),
+ c(0.7,0.9), c(0.3,0.8) )
>

In version 2.7 there is also the option to use the clip function (instead of clipplot in TeachingDemos) like:

> clip( 0.3, 0.8, 0.9, 1.0 )
> image(x,y,z, col=topo.colors(100), add=TRUE)

However the help for "clip" notes that it can be hard to predict when the clipping region will be reset, so this sometimes works (my tests had it work if I did the above 2 lines after the subplot example) and sometimes does not (my tests did not work when used after the clipplot example, or on a new plot).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111
 
 


> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of tom soyer
> Sent: Tuesday, April 08, 2008 12:24 PM
> To: r-help_at_r-project.org
> Subject: [R] diagonally fill a rectangle with color gradient
>
> Hi,
>
> Is it possible to diagonally fill a rectangle with a color
> gradient? I noticed that the gradient.rect of plotrix could
> fill a rect either up and down or from side to side. I am
> looking for something similar but fills diagonally instead,
> e.g., from the upper left corner to the bottom right.
> Does anyone know how to do it in R?
>
> Thanks,
>
> --
> Tom
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
______________________________________________ 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 Wed 09 Apr 2008 - 19:01:04 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 Wed 09 Apr 2008 - 19:30:27 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