[R] Problems with lattice plot

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Jan 18 12:35:28 CET 2008


Dear Francesc,

This is rather easy to do with the ggplot2 package.

library(ggplot2)
dataset <- expand.grid(x = 1:10, y = 1:50)
dataset$z <- runif(nrow(dataset))
ggplot(data = dataset, aes(x = x, y = y, fill = z)) + geom_tile() + scale_fill_gradient(low="white", high="black") + coord_equal()

Have a look at the ggplot2 website (http://had.co.nz/ggplot2/) for more examples.

HTH,

Thierry 


----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org] Namens Francesc Montané
Verzonden: vrijdag 18 januari 2008 12:01
Aan: r-help op r-project.org
Onderwerp: [R] Problems with lattice plot

Hello useRs,



I have some problems when I try to plot a lattice. The lattice has 200 
columns (X value) and 5 rows (Y value), with a total of 1000 squares. I 
want to plot this lattice with the squares having different colours 
according to a variable value.



The variable I want to plot is cover value of a shrub, and it has values 
between 0 and 1. I want to plot the squares with value 1, black, the 
squares with values 0, white, and the values between 0 and 1 with grey, 
more or less dark depending on its proximity to 1 (dark grey) or 0 
(light grey). I have tried this:



plot(x=transect41$x,y=transect41$y,asp=1,

xlab="",ylab="",

axes=F,pch=22,cex=1.01,lwd=0.05,

bg=gray(1-transect41$CoverValue),col=gray(0.75))

plot(pch=22,cex=1.01,lwd=0.05)



When I plot the lattice, I have problems because the squares have 
different sizes. Moreover, some of them look like a rectangle and not a 
square.

What can I do to solve this problem?



Many thanks in advance.



Francesc

______________________________________________
R-help op 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