Monica Palaseanu-Lovejoy
2004-Mar-24 15:05 UTC
[R] colors, lines, characters .... documentation
Hi, Very so often when i am plotting something, doing a histogram, or whatever i am struggling to find out which are the numbers for different colors, palette names, types of lines, symbols, etc. Is there any documentation on line with all these numbers / names and the associated symbol / color??? For example if i am using the command image it uses a palette from red to yellow, with red the lowest value, and yellow the highest value. What if i want a reverse palette, with green the lowest value and yellow middle values and red highest value??? Or much more simple, just yellow lowest value and red highest value??? Thank you for assistance, Monica
Hi, many questions at once there, but here some help regarding *symbols*. I've pasted a function plotSymbols() that shows all symbols available. Note that the the symbols pch >= 128 are system dependent so you should not expect them to look the same on Windows, Mac and Unix. Try also plotSymbols(TRUE). To turn of the click-bell do 'options(locatorBell=FALSE)' (see ?locator). Cheers Henrik ---------------------------------------------------- BEGIN code ---------------------------------------------------- plotSymbols <- function(interactive=FALSE) { ASCII <- c("\000", sapply(1:255, function(i) parse(text=paste("\"\\", structure(i,class="octmode"), "\"", sep=""))[[1]])); intToChar <- function(i) { ASCII[i %% 256 + 1]; } interactive <- interactive && interactive(); i <- 0:255; ncol <-16; top <- 3 + 2*interactive; opar <- par(cex.axis=0.7, mar=c(3,3,top,3)+0.1) on.exit(par(opar)) plot(i%%ncol,1+i%/%ncol, pch=i, xlim=c(0,ncol-1), xlab="", ylab="", axes=FALSE); axis(1, at=0:15) axis(2, at=1:16, labels=0:15*16, las=2) axis(3, at=0:15) axis(4, at=1:16, labels=0:15*16+15, las=2) if (interactive) { title(main="Click on a symbol to add it to the data frame. Click in margin to quit!", cex.main=0.8, line=3.5); } if (interactive) { df <- list(); usr <- par("usr"); ready <- FALSE; while (!ready) { click <- locator(n=1); x <- click$x; y <- click$y - 1; ready <- !(x > 0.5 && x < 15.5 && y > 0.5 && y < 15.5); if (!ready) { x <- round(x); y <- round(y); z <- 16*y + x; ch <- intToChar(z); dec <- as.character(z); hex <- intToHex(z); oct <- intToOct(z); spc <- paste(rep("0", 2-nchar(hex)), collapse=""); hex <- paste(spc, hex, sep=""); spc <- paste(rep("0", 3-nchar(oct)), collapse=""); oct <- paste(spc, oct, sep=""); df$ch <- c(df$ch , ch ); df$dec <- c(df$dec, dec); df$hex <- c(df$hex, hex); df$oct <- c(df$oct, oct); if (nchar(ch) == 0) ch <- " "; spc <- paste(rep(" ", 3-nchar(dec)), collapse=""); dec <- paste(spc, dec, sep=""); cat("Selected ASCII character '", ch, "' ", dec, " 0x", hex, " \\", oct, "\n", sep=""); } } return(df); } invisible() } # plotSymbols() ---------------------------------------------------- END code ----------------------------------------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Monica > Palaseanu-Lovejoy > Sent: den 24 mars 2004 16:06 > To: r-help at stat.math.ethz.ch > Subject: [R] colors, lines, characters .... documentation > > > Hi, > > Very so often when i am plotting something, doing a histogram, or > whatever i am struggling to find out which are the numbers for > different colors, palette names, types of lines, symbols, etc. Is > there any documentation on line with all these numbers / names > and the associated symbol / color??? > > For example if i am using the command image it uses a palette > from red to yellow, with red the lowest value, and yellow thehighest> value. What if i want a reverse palette, with green the lowest value> and yellow middle values and red highest value??? Or much more > simple, just yellow lowest value and red highest value??? > > Thank you for assistance, > > Monica > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailma> n/listinfo/r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Hello,> -----Original Message----- > From: Monica Palaseanu-Lovejoy > [SMTP:monica.palaseanu-lovejoy at stud.man.ac.uk] > Sent: Wednesday, March 24, 2004 4:06 PM > To: r-help at stat.math.ethz.ch > Subject: [R] colors, lines, characters .... documentation > > Hi, > > Very so often when i am plotting something, doing a histogram, or > whatever i am struggling to find out which are the numbers for > different colors, palette names, types of lines, symbols, etc. Is > there any documentation on line with all these numbers / names > and the associated symbol / color??? >what I found to be quite useful is found in the library Hmisc. (Thanks, Frank Harrell!) library(Hmisc) show.col() show.pch() And if you look at the definitions of these functions, it might be quite easy to modify them for your exact needs. Hope this helps, Roland +++++ This mail has been sent through the MPI for Demographic Rese...{{dropped}}
See ?palette ?colors the colors used when you use number are those in palette: > palette() [1] "black" "red" "green3" "blue" "cyan" "magenta" "yellow" "gray" > plot(1:20,col=1:20) You can define your own palette with colors available in colors: > palette(colors()[sample(1:657,20)]) > palette() [1] "peachpuff" "purple2" "gray37" "paleturquoise4" [5] "hotpink" "mediumspringgreen" "gray82" "red2" [9] "purple3" "cadetblue2" "gray55" "red" [13] "tomato4" "gray39" "rosybrown" "darkorange1" [17] "gray27" "lemonchiffon3" "oldlace" "honeydew" > plot(1:20,col=1:20) For the image function, you can enter your own vector of colors (by default, col = heat.colors(12)) and one way to define your colors is to use 'rgb' function with values for Red - Green - Blue. Sincerely, At 10:05 24/03/2004, Monica Palaseanu-Lovejoy wrote:>Hi, > >Very so often when i am plotting something, doing a histogram, or >whatever i am struggling to find out which are the numbers for >different colors, palette names, types of lines, symbols, etc. Is >there any documentation on line with all these numbers / names >and the associated symbol / color??? > >For example if i am using the command image it uses a palette >from red to yellow, with red the lowest value, and yellow the highest >value. What if i want a reverse palette, with green the lowest value >and yellow middle values and red highest value??? Or much more >simple, just yellow lowest value and red highest value??? > >Thank you for assistance, > >Monica > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlSt?phane DRAY -------------------------------------------------------------------------------------------------- D?partement des Sciences Biologiques Universit? de Montr?al, C.P. 6128, succursale centre-ville Montr?al, Qu?bec H3C 3J7, Canada Tel : 514 343 6111 poste 1233 E-mail : stephane.dray at umontreal.ca -------------------------------------------------------------------------------------------------- Web http://www.steph280.freesurf.fr/
Here is a little function that will show available colors in groups of 100 at a time. I've only tested it in an X windows environment. function (indx = 0:6) { for (ii in unique(indx)) { is <- 100 * ii + 1:100 if (min(is) > length(colors())) { cat("Maximum value of arg is", floor(length(colors())/100), "\n") return(NULL) } foo <- matrix(colors()[is], nrow = 10) par(mar = c(3, 3, 0.25, 0.25)) plot(1:10, 1:10, type = "n", yaxt = "n", xlab = "", ylab = "") axis(2, at = 1:10, lab = 10:1) for (j in 1:10) { for (i in 1:10) { points(j, 11 - i, col = foo[i, j], pch = 16, cex = 4) text(j, 11 - i - 0.3, foo[i, j], cex = 0.8) } } if (length(indx) > 1 & ii < max(indx)) readline(paste("Currently showing group", ii, " CR to continue ")) } invisible(foo) } -Don At 3:05 PM +0000 3/24/04, Monica Palaseanu-Lovejoy wrote:>Hi, > >Very so often when i am plotting something, doing a histogram, or >whatever i am struggling to find out which are the numbers for >different colors, palette names, types of lines, symbols, etc. Is >there any documentation on line with all these numbers / names >and the associated symbol / color??? > >For example if i am using the command image it uses a palette >from red to yellow, with red the lowest value, and yellow the highest >value. What if i want a reverse palette, with green the lowest value >and yellow middle values and red highest value??? Or much more >simple, just yellow lowest value and red highest value??? > >Thank you for assistance, > >Monica > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA
On 24 Mar 2004 at 15:05, Monica Palaseanu-Lovejoy wrote:> Hi, > > Very so often when i am plotting something, doing a histogram, or > whatever i am struggling to find out which are the numbers for > different colors, palette names, types of lines, symbols, etc. Is > there any documentation on line with all these numbers / names and the > associated symbol / color??? >I do usually something like: plot(1:20, rep(1,20), pch=1:20, col=1:20) plot(1:20, 1:20, type="n") for (i in 1:20) { + lines( c(1,20), c(i,i), lty=i) }> For example if i am using the command image it uses a palette > from red to yellow, with red the lowest value, and yellow the highest > value. What if i want a reverse palette, with green the lowest value: palette(rev(palette())) palette() [1] "gray" "yellow" "magenta" "cyan" "blue" "green3" "red" [8] "black"> and yellow middle values and red highest value??? Or much more simple, > just yellow lowest value and red highest value???See also the CRAN package RColorBrewer Kjetil Halvorsen> > Thank you for assistance, > > Monica > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html