Dear Contributors: I have the next matrix: "X" "Y" "Z" 1 2 526 2 5 723 3 10 110 4 7 1110 5 9 34 6 8 778 7 1 614 8 4 876 9 6 249 10 3 14 I want to order the matrix from bigest Z (1110) to lower Z (14). Then I want to asign a color scale vector from blue ( bigest Z) to orange (lower Z), and then I want to make a plot with the X vs.Y coordinates of the matrix, with the number correspondent to Z in every point, each number coloured with the assigned colour scale colour. Is this doable????? Thanks in advance again, Juan Pablo
One way to do this may be to create the right image and show it. I have never user R for image processing so I can not provide any details, but I would have done the following: Create a 100x100 (or 1000x1000) white image. Then (assuming that it is a 100x1000 image), for each pair of your (x,y) you can paint the pixel (10x,10y) with the appropriate color. --- Juan Pablo Fededa <jpfededa at gmail.com> wrote:> Dear Contributors: > > I have the next matrix: > > "X" "Y" "Z" > > 1 2 526 > 2 5 723 > 3 10 110 > 4 7 1110 > 5 9 34 > 6 8 778 > 7 1 614 > 8 4 876 > 9 6 249 > 10 3 14 > > I want to order the matrix from bigest Z (1110) to > lower Z (14). > Then I want to asign a color scale vector from blue > ( bigest Z) to > orange (lower Z), and then I want to make a plot > with the X vs.Y > coordinates of the matrix, with the number > correspondent to Z in every > point, each number coloured with the assigned colour > scale colour. > Is this doable????? > Thanks in advance again, > > > > Juan Pablo > > ______________________________________________ > 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. >
Hi Juan, Assuming that your data frame is named df, something like the following should work: library(ggplot) qplot(X, Y, data = df, colour = Z, label = Z, geom = "text") + scale_colour_continuous(low="orange", high = "blue") You can find out more about ggplot2 at http://had.co.nz/ggplot2. Hadley On 11/22/07, Juan Pablo Fededa <jpfededa at gmail.com> wrote:> Dear Contributors: > > I have the next matrix: > > "X" "Y" "Z" > > 1 2 526 > 2 5 723 > 3 10 110 > 4 7 1110 > 5 9 34 > 6 8 778 > 7 1 614 > 8 4 876 > 9 6 249 > 10 3 14 > > I want to order the matrix from bigest Z (1110) to lower Z (14). > Then I want to asign a color scale vector from blue ( bigest Z) to > orange (lower Z), and then I want to make a plot with the X vs.Y > coordinates of the matrix, with the number correspondent to Z in every > point, each number coloured with the assigned colour scale colour. > Is this doable????? > Thanks in advance again, > > > > Juan Pablo > > ______________________________________________ > 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. >-- http://had.co.nz/
Juan Pablo Fededa wrote:> Dear Contributors: > > I have the next matrix: > > "X" "Y" "Z" > > 1 2 526 > 2 5 723 > 3 10 110 > 4 7 1110 > 5 9 34 > 6 8 778 > 7 1 614 > 8 4 876 > 9 6 249 > 10 3 14 > > I want to order the matrix from bigest Z (1110) to lower Z (14). > Then I want to asign a color scale vector from blue ( bigest Z) to > orange (lower Z), and then I want to make a plot with the X vs.Y > coordinates of the matrix, with the number correspondent to Z in every > point, each number coloured with the assigned colour scale colour. > Is this doable?????Sure, but I don't think you need to order the rows to do it: library(plotrix) jpf<-read.csv("jpf.csv") plot(jpf$X,jpf$Y,main="Test of color/text plot", type="n") text(jpf$X,jpf$Y,labels=jpf$Z, col=color.scale(jpf$Z,extremes=c("orange","blue"))) Note that the "extremes" argument will only work properly in the latest version of plotrix. Jim
Within the base package collection, see ?colorRamp and ?colorRampPalette Then or.to.blue<-colorRampPalette(c("orange","green","blue")) #green included to avoid muddy blues plot(df$X, df$Y,type="n") text(df$X, df$Y, labels=df$Z, col=or.to.blue(length(df$Z))[rank(df$Z)]) You don't need to order by Z to do this, but if you want that for another reason, see ?order and try oo<-order(df$Z) df[oo,] Steve E>>> "hadley wickham" <h.wickham at gmail.com> 23/11/2007 01:02:13 >>>Hi Juan, Assuming that your data frame is named df, something like the following should work: library(ggplot) qplot(X, Y, data = df, colour = Z, label = Z, geom = "text") + scale_colour_continuous(low="orange", high = "blue") You can find out more about ggplot2 at http://had.co.nz/ggplot2. Hadley On 11/22/07, Juan Pablo Fededa <jpfededa at gmail.com> wrote:> Dear Contributors: > > I have the next matrix: > > "X" "Y" "Z" > > 1 2 526 > 2 5 723 > 3 10 110 > 4 7 1110 > 5 9 34 > 6 8 778 > 7 1 614 > 8 4 876 > 9 6 249 > 10 3 14 > > I want to order the matrix from bigest Z (1110) to lower Z (14). > Then I want to asign a color scale vector from blue ( bigest Z) to > orange (lower Z), and then I want to make a plot with the X vs.Y > coordinates of the matrix, with the number correspondent to Z inevery> point, each number coloured with the assigned colour scale colour. > Is this doable????? > Thanks in advance again, > > > > Juan Pablo > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/ ______________________________________________ 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. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}