Benoit Gendreau-Berthiaume
2013-Feb-28 23:54 UTC
[R] Ploting different values with different colors
Hello I am trying to plot a 20 x 20 grid of points with the colors of each point refering to percent cover of that specific point So basically the point are all the same size and their position on the graph is base on their coordinates (x,y). I want the color (a grey scale from white=0 to black =100) to represent the values of each of these point (cover) Here is what my data looks like x y cover A1 0 95 3.0 A2 5 95 0.5 A3 10 95 10.0 ...etc Up to now I have tried plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[x[,3]]) I put 8 after heat colors because their are 8 different values in my cover column My problem is that I only get one color out this line of code. Regardless of which number I put after heat.colors I always have the same quadrats colored with only one color. Any idea of how to get 8 colors in my graph? and how to make sure they are associated with the good cover values? Thanks Benoit Gendreau-Berthiaume PhD Candidate Department of Renewable Resources University of Alberta [[alternative HTML version deleted]]
Hi> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Benoit Gendreau-Berthiaume > Sent: Friday, March 01, 2013 12:54 AM > To: r-help at r-project.org > Subject: [R] Ploting different values with different colors > > Hello I am trying to plot a 20 x 20 grid of points with the colors of > each point refering to percent cover of that specific point > > So basically the point are all the same size and their position on the > graph is base on their coordinates (x,y). I want the color (a grey > scale from white=0 to black =100) to represent the values of each of > these point > (cover) > > Here is what my data looks like > x y cover > A1 0 95 3.0 > A2 5 95 0.5 > A3 10 95 10.0 > ...etc > Up to now I have tried > plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[x[,3]]) IWell, you did not provide much info to let us help you. What is e.g. x[,3]? I can only guess, that it is the same as cover variable. If yes, you need to change it to ordered factor, if you want to use it for selection. something like sel.col<-ordered(x[,3]) plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[as.numeric(sel.col)]) can do what you want if there is really only 8 unique values. You could also consider some graphic devices which can use alpha transparency ??alpha Regards Petr> put 8 after heat colors because their are 8 different values in my > cover column > > My problem is that I only get one color out this line of code. > Regardless of which number I put after heat.colors I always have the > same quadrats colored with only one color. > > Any idea of how to get 8 colors in my graph? > and how to make sure they are associated with the good cover values? > > Thanks > Benoit Gendreau-Berthiaume > PhD Candidate > Department of Renewable Resources > University of Alberta > > [[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.
On 03/01/2013 10:54 AM, Benoit Gendreau-Berthiaume wrote:> Hello I am trying to plot a 20 x 20 grid of points with the colors of each > point refering to percent cover of that specific point > > So basically the point are all the same size and their position on the > graph is base on their coordinates (x,y). I want the color (a grey scale > from white=0 to black =100) to represent the values of each of these point > (cover) > > Here is what my data looks like > x y cover > A1 0 95 3.0 > A2 5 95 0.5 > A3 10 95 10.0 > ...etc > Up to now I have tried > plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[x[,3]]) > I put 8 after heat colors because their are 8 different values in my cover > column > > My problem is that I only get one color out this line of code. Regardless > of which number I put after heat.colors I always have the same quadrats > colored with only one color. > > Any idea of how to get 8 colors in my graph? > and how to make sure they are associated with the good cover values? >Hi Benoit, This can be done with a number of R functions. I will shamelessly demonstrate one that I wrote myself: Q<-data.frame(x=sample(0:100,20),y=sample(0:100,20), cover=runif(20,0,100)) library(plotrix) Qcolors<-color.scale(Q$cover,extremes=c("white","black"), xrange=c(0,100)) plot(Q$x,Q$y,pch=21,col="black",bg=Qcolors,cex=2) Jim