Re: [R] Setting the colors of lines in a trellis plot...
The col command worked. Thanks! Jamie On 7/10/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Use col= to specify colors, e.g. > > library(lattice) > x <- 1:12 > xyplot(x ~ x, group = gl(3,4), col = 1:3, type = "l", auto.key = TRUE) > > If this is not sufficiently close to your problem > 1. cut your example down to a *minimal* size and > 2. provide it as *self contained* and > 3. *reproducible* code. > > On 7/10/06, Jamieson Cobleigh <[EMAIL PROTECTED]> wrote: > > With some help from those with expertise on this list, I managed to > > produce a plot using trellis that looked like I wanted it to look. > > Now, I need to take the same plot and make the lines on it color, but > > I want to specify the color for the lines myself. > > > > I've managed to make the key use the colors I want. I've managed to > > make the symbols of the actual plot use the colors I want. But I have > > been unable to find the correct incantation to make the lines of the > > actual plot use the colors I want. Here's the relevant section of > > code: > > > > mycolors <- c("black", "darkgreen", "red") > > > > mylines <- Rows(superpose.line, 1:numlines); > > mylines$col <- mycolors > > > > mysymbols <- Rows(superpose.symbol, 1:numlines); > > mysymbols$pch <- c(15:18)[1:numlines] > > mysymbols$col <- mycolors > > > > print(xyplot( > >panel = panel.superpose, > >log10(states) ~ size, > >groups=category, > >data=data, > >type='b', > >lwd = 2, > >par.settings = list(superpose.symbol=mysymbols), > >ylim=c(y_min, y_max), > >scales = list(tck=c(1, 0), axs="r", > > > > x=list(tick.number=(xmax - xmin + 1), at=xmin:xmax, > > labels=xmin:xmax, cex=1.75), > > > > y=list(axs="r", rot=c(90, 0), labels=y_labels, > > at=y_at, cex=1.75 > > ) > > ), > >key = list ( > > text = list(levels(data$category)), > > lines = list(type="b", > > lty=mylines$lty, > > pch=mysymbols$pch, > > cex=rep(1.25, numlines), > > col=mylines$col), > > x = .98, > > y = .25, > > corner=c(1,0) > >), > >xlab = list(label="System Size", cex=2), > >ylab = list(label="States", cex=2), > > )) > > > > > > Can anyone help me out with this? > > > > Thanks! > > > > Jamie > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Setting the colors of lines in a trellis plot...
With some help from those with expertise on this list, I managed to produce a plot using trellis that looked like I wanted it to look. Now, I need to take the same plot and make the lines on it color, but I want to specify the color for the lines myself. I've managed to make the key use the colors I want. I've managed to make the symbols of the actual plot use the colors I want. But I have been unable to find the correct incantation to make the lines of the actual plot use the colors I want. Here's the relevant section of code: mycolors <- c("black", "darkgreen", "red") mylines <- Rows(superpose.line, 1:numlines); mylines$col <- mycolors mysymbols <- Rows(superpose.symbol, 1:numlines); mysymbols$pch <- c(15:18)[1:numlines] mysymbols$col <- mycolors print(xyplot( panel = panel.superpose, log10(states) ~ size, groups=category, data=data, type='b', lwd = 2, par.settings = list(superpose.symbol=mysymbols), ylim=c(y_min, y_max), scales = list(tck=c(1, 0), axs="r", x=list(tick.number=(xmax - xmin + 1), at=xmin:xmax, labels=xmin:xmax, cex=1.75), y=list(axs="r", rot=c(90, 0), labels=y_labels, at=y_at, cex=1.75 ) ), key = list ( text = list(levels(data$category)), lines = list(type="b", lty=mylines$lty, pch=mysymbols$pch, cex=rep(1.25, numlines), col=mylines$col), x = .98, y = .25, corner=c(1,0) ), xlab = list(label="System Size", cex=2), ylab = list(label="States", cex=2), )) Can anyone help me out with this? Thanks! Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Adding polygons to a barplot
Thanks! That worked. Jamie On 3/8/06, Marc Schwartz (via MN) <[EMAIL PROTECTED]> wrote: > On Wed, 2006-03-08 at 14:02 -0500, Jamieson Cobleigh wrote: > > I have a barplot I have created using barplot2 and I have been able to > > add points and lines (using the points and lines methods, > > respectively). I now need to add some polygons (triangles in > > particular), that I want to be shaded to match bars in the plot. I > > can get the coordinates of the corners of the triangles, but don't > > know how to draw the triangles. I know there is the grid.polygon > > method, but I don't know how to get it to draw on my plot. Any help > > would be appreciated. > > > > Thanks! > > > > Jamie > > There is a polygon() function in base R graphics. It supports a > 'density' argument in the same fashion as barplot()/barplot2(). > > See ?polygon > > help.search("polygon") would have gotten you there. > > HTH, > > Marc Schwartz > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Adding polygons to a barplot
I have a barplot I have created using barplot2 and I have been able to add points and lines (using the points and lines methods, respectively). I now need to add some polygons (triangles in particular), that I want to be shaded to match bars in the plot. I can get the coordinates of the corners of the triangles, but don't know how to draw the triangles. I know there is the grid.polygon method, but I don't know how to get it to draw on my plot. Any help would be appreciated. Thanks! Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R plots in PowerPoint
I have some plots that I generating using R (using trellis, plot, and barplot2) that I want to include in a PowerPoint presentation I am giving. My computer is running OS X. I find that presentations are easier to read when there is light text on a dark background and would like to generate plots that fit that style. The plots I am generating are all grayscale. Is there an easy way to get R to "reverse" the plots, to make black into white and white into black? Also, is there a way to have R generate images where the background color is transparent? Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Width of bars in barplot2
Thanks. That was all I needed. Jamie On 3/1/06, Marc Schwartz (via MN) <[EMAIL PROTECTED]> wrote: > Unless you have modified the 'width' argument, the default width is 1. > > Thus the sides of the bars are the centers +/- 0.5. > > If you modified the width argument, then the widths are set to the > vector assigned. > > This behavior is the same in barplot() and barplot2() by design. > > As an example: > > # Draw a barplot. adjust the y axis to make some room > # above the bars > mp <- barplot2(1:10, ylim = c(0, 12)) > > # Draw lines showing the bar width limits > arrows(mp - 0.5, 2:11, mp + 0.5, 2:11, angle = 90, code = 3) > > > HTH, > > Marc Schwartz > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Width of bars in barplot2
I'm using barplot2 to plot some data. Is there any way to determine the width of the bars in the generated plot? I know that barplot2 returns a list of the coordinates of the center of each bar, but since there is some white space between each bar, I don't know how to get the width of each bar. Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Copying from graphics window in OS X
I just tried using Ctrl-C to do a copy a plot from a graphic window using the Cocoa version of OS X that you can download from the link below and I was able to paste the plot into a document. Jamie On 9/15/05, Jamieson Cobleigh <[EMAIL PROTECTED]> wrote: > Also, why are you running R from an XTerm? There is an OS X native > version of R that might be better integrated with OS X for doing > screen captures: >http://cran.stat.ucla.edu/bin/macosx/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Copying from graphics window in OS X
You can try FreeSnap, a screen capture program for OS X: http://www.efritz.net/software.html Also, why are you running R from an XTerm? There is an OS X native version of R that might be better integrated with OS X for doing screen captures: http://cran.stat.ucla.edu/bin/macosx/ Jamie On 9/15/05, Chris Wiita <[EMAIL PROTECTED]> wrote: > I'm running R from an Xterm window is OSX-Tiger. Graphical windows > appear as they should, but I'm having trouble copying from them--using > cmd+c or the Copy option in the Edit menu won't place the graph in the > clipboard (when I paste into a running OS X app, I get whatever was the > last copied thing from a non-x11 window). Any ideas on how to copy from > a xterm-launched graphical window? I can copy/paste into and out of the > xterm command line, but I can't get anything from a graphical window. > > Thanks! > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Spacing and margins in lattice...
That did the trick. Thanks! Jamie On 9/1/05, Sundar Dorai-Raj <[EMAIL PROTECTED]> wrote: > > > Jamieson Cobleigh wrote: > > Similar to my last question, I want to tighten up the spacing and > > margins in a plot I am doing with lattice. > > > > Here are the commands I'm using: > > > > data <- data.frame(x=c(1:3, 1:3), y=c(1:3, 1:3*2), > > cat=c("foo","foo","foo","bar", "bar","bar")) > > > > xyplot(panel=panel.superpose, y~x, data=data, groups=cat, type="b", > > scales=list(tck=c(2,0), axs="r", cex=c(1,0))) > > > > I know that par(mar=c(2,2,1,1)) would do what I want with plot. Is > > there something similar for xyplot/lattice that can reduce the size of > > the margins of the plot? > > > > Thanks! > > > > Jamie > > > > Hi, Jamie, > > Will the following work for you? > > library(lattice) > data <- data.frame(x = c(1:3, 1:3), y = c(1:3, 1:3*2), > cat = c("foo","foo","foo","bar", "bar","bar")) > > trellis.par.set(theme = col.whitebg()) > > lw <- list(left.padding = list(x = 0, units = "inches")) > lw$right.padding <- list(x = -0.1, units = "inches") > lh <- list(bottom.padding = list(x = 0, units = "inches")) > lh$top.padding <- list(x = -0.2, units = "inches") > > lattice.options(layout.widths = lw, layout.heights = lh) > xyplot(y ~ x, data, groups = cat, type="b") > > HTH, > > --sundar > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Spacing and margins in lattice...
Similar to my last question, I want to tighten up the spacing and margins in a plot I am doing with lattice. Here are the commands I'm using: data <- data.frame(x=c(1:3, 1:3), y=c(1:3, 1:3*2), cat=c("foo","foo","foo","bar", "bar","bar")) xyplot(panel=panel.superpose, y~x, data=data, groups=cat, type="b", scales=list(tck=c(2,0), axs="r", cex=c(1,0))) I know that par(mar=c(2,2,1,1)) would do what I want with plot. Is there something similar for xyplot/lattice that can reduce the size of the margins of the plot? Thanks! Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Spacing and margins in plot
That worked and gave me enough information so to make it look exactly the way I want. Thanks! Jamie On 9/1/05, Chuck Cleland <[EMAIL PROTECTED]> wrote: > How about this: > > par(mar=c(2,4,1,1)) > > plot(c(1,2,2,3,3,3), type="p", pch=20, ylab="Y Label", xlab="", xaxt="n") > > mtext(side=1, line=0.5, "X Label") > > hope it helps, > > Chuck > > Jamieson Cobleigh wrote: > > If I use the following command to plot points: > > > > plot(c(1,2,2,3,3,3), type="p", pch=20, ylab="Y Label", xlab="X Label", > > xaxt="n") > > > > there is a large amount of space between the label "X Label" and the > > actual x-axis. If I change the xaxt="n" to xaxt="s", the label "X > > Label" don't move at all. Is there a way to get the label "X Label" > > closer to the x-axis when xaxt="n"? > > > > > > > > The plot I am generating is going to be included in a paper I am > > writing. I can cause the plot to be saved in a PDF file by doing the > > following: > > > > pdf("foo.pdf", width=5.5, height=4.25, onefile=FALSE) > > > > plot(c(1,2,2,3,3,3), type="p", pch=20, ylab="Y Label", xlab="X Label", > > xaxt="n") > > > > dev.off(); > > > > In the resulting file, there is a lot of whitespace around the graph, > > particularly between the top line of the plot area and the top of the > > page. Since I am including these plots in a paper, I want them to be > > as large as possible and not take up any extra space. Is there a way > > to get R to draw a plot that goes all the way to the margins of the > > print area? > > > > Jamie > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > -- > Chuck Cleland, Ph.D. > NDRI, Inc. > 71 West 23rd Street, 8th floor > New York, NY 10010 > tel: (212) 845-4495 (Tu, Th) > tel: (732) 452-1424 (M, W, F) > fax: (917) 438-0894 > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Spacing and margins in plot
If I use the following command to plot points: plot(c(1,2,2,3,3,3), type="p", pch=20, ylab="Y Label", xlab="X Label", xaxt="n") there is a large amount of space between the label "X Label" and the actual x-axis. If I change the xaxt="n" to xaxt="s", the label "X Label" don't move at all. Is there a way to get the label "X Label" closer to the x-axis when xaxt="n"? The plot I am generating is going to be included in a paper I am writing. I can cause the plot to be saved in a PDF file by doing the following: pdf("foo.pdf", width=5.5, height=4.25, onefile=FALSE) plot(c(1,2,2,3,3,3), type="p", pch=20, ylab="Y Label", xlab="X Label", xaxt="n") dev.off(); In the resulting file, there is a lot of whitespace around the graph, particularly between the top line of the plot area and the top of the page. Since I am including these plots in a paper, I want them to be as large as possible and not take up any extra space. Is there a way to get R to draw a plot that goes all the way to the margins of the print area? Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Labels on axes with log scales with lattice
I using lattice to make some plots and I want to make the y-axis on some of these plots use a log scale. In the following plot: x <- 1:10 y <- 2^x xyplot(log10(y) ~ x) I get tick marks on the y-axis at 0.5, 1.0, 1.5, 2.0, 2.5, and 3.0. I would rather have just 3 tick marks at 1.0, 2.0, and 3.0 but labeled 10, 100, and 1000. I know this can be done using the "at" and "labels" parameters to the "x" parameter to the "scales" parameter to the "xyplot" command. xyplot(log10(y) ~ x, scales=list(y=list(at=c(1, 2, 3), labels=c(10, 100, 1000 My problem is that I am making multiple plots and cannot set the labels on each plot individually. I need to automate the computation of the "at" and "labels" parameters. I think the "axTicks" command can compute the information I need to set "at" and "labels" correctly, but I am having trouble determining how to set its parameters to make it compute the information I need. Perhaps "pretty" might work to, but "axTicks" seems better designed for handling logarithmic axes. Does anyone have any suggestions? Thanks in advance! Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Saving trellis output to files in scripts...
Thanks, that worked. I see now where it says that in the help for xyplot, however, it wasn't obvious to me before. Jamie On 8/9/05, Liaw, Andy <[EMAIL PROTECTED]> wrote: > This is in the FAQ: You need to wrap any trellis calls in functions or > scripts in print(). > > Andy > > > From: Jamieson Cobleigh > > > > With much help from Chuck Cleland, I was able to get xyplot to > > generate the plot I wanted. I'm trying to write a script (that can be > > read using source("file")) to create the plots I want and save them to > > files. > > > > If I type the following lines into the R (in interactive mode), the > > correct plot gets saved into the file myfile.ps with a size of 4,096 > > bytes: > > > > > > require(lattice) > > > > trellis.device("postscript", file="myfile.ps", color=FALSE, > > paper="letter", horizontal=TRUE, onefile=TRUE) > > > > xyplot(y ~ x, type="b", data.frame(x=1:5, y=5:1)) > > > > dev.off() > > > > > > However, if I put the same lines into a file, "temp.txt", and type > > source("temp.txt") into R, then myfile.ps ends up with a size of 2,332 > > bytes and shows a blank page when loaded into ghostscript. > > > > When run using source, it looks like the device is not getting closed > > correctly since if I type source("temp.txt") and then dev.list() R > > responds: "postscript 2" > > > > If I type dev.off(), the file size then increases to 4,277 bytes, but > > then the ps file is malformed. > > > > Anyone know how to make this work? > > > > Jamie > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > > > > -- > Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Saving trellis output to files in scripts...
With much help from Chuck Cleland, I was able to get xyplot to generate the plot I wanted. I'm trying to write a script (that can be read using source("file")) to create the plots I want and save them to files. If I type the following lines into the R (in interactive mode), the correct plot gets saved into the file myfile.ps with a size of 4,096 bytes: require(lattice) trellis.device("postscript", file="myfile.ps", color=FALSE, paper="letter", horizontal=TRUE, onefile=TRUE) xyplot(y ~ x, type="b", data.frame(x=1:5, y=5:1)) dev.off() However, if I put the same lines into a file, "temp.txt", and type source("temp.txt") into R, then myfile.ps ends up with a size of 2,332 bytes and shows a blank page when loaded into ghostscript. When run using source, it looks like the device is not getting closed correctly since if I type source("temp.txt") and then dev.list() R responds: "postscript 2" If I type dev.off(), the file size then increases to 4,277 bytes, but then the ps file is malformed. Anyone know how to make this work? Jamie __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Help with doing overlays plots...
I have a data frame with three columns, type (a factor with two values: "Monolithic" and "Compositional"), size (numeric), and states (numeric). I want to create a plot where size goes on the x-axis and states goes on the y-axis. In this plot, I want two lines, one where the type is "Monolithic" and one where the type is "Compositional". I think this can be done by using the plot command to plot the line for one of the two types (setting the xlim and ylim parameters to ensure the plot area is large enough to hold all of the points). Then, I can use the lines and points commands to add the second line onto the plot. However, I don't want to have to specify the legend manually. I want something in R that does what can be done in SAS by using "plot states*size=type" in "proc gplot". Here is a dump of my data set: tmp <- structure(list(type = structure(as.integer(c(2, 2, 2, 1, 1, 1, 1, 1)), .Label = c("Compositional", "Monolithic"), class = "factor"), size = as.integer(c(2, 3, 4, 2, 3, 4, 5, 6)), states = as.integer(c(4910, 336026, 37526650, 4016, 44941, 310553, 8260254, 144145585 ))), .Names = c("type", "size", "states"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "data.frame") __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html