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]]

Hi tom soyer wrote:> 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?Do you mean something like this ... ? library(grid) pushViewport(viewport(width=.5, height=.5, clip="on")) pushViewport(viewport(width=2, height=2, angle=45)) grid.rect(y=100:1/100, just="top", gp=gpar(col=NA, fill=colorRampPalette(c("blue", "green"), space="Lab")(100))) Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/

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. >

### Possibly Parallel Threads

- Aligning Diagonally Oriented Labels Under Bar Chart
- Which gls models to use?
- Plotcorr: colour the ellipses to emphasize the differences
- Is there something wrong with R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"?
- Histogram with different colors for different portions