[R] Legend issue with ggplot2
Dear useRs, I'm struggling with the new version of ggplot2. In the previous version I did something like this. But now this yield an error (object fill not found). library(ggplot2) dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10)) dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group] dummy$min - dummy$y - 5 dummy$max - dummy$y + 5 ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) + geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y = min, colour = fill)) When I adjust the code to the line below, it works again. But this time with two legend keys for group. Any idea how to display only one legend key for group? The ggplot-code aboved yielded only on legend key. ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group, fill = group)) + geom_ribbon() + geom_line(aes(y = max)) + geom_line(aes(y = min)) Thanks, 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 [EMAIL PROTECTED] 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 __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend issue with ggplot2
On 9/3/07, ONKELINX, Thierry [EMAIL PROTECTED] wrote: Dear useRs, I'm struggling with the new version of ggplot2. In the previous version I did something like this. But now this yield an error (object fill not found). library(ggplot2) dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10)) dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group] dummy$min - dummy$y - 5 dummy$max - dummy$y + 5 ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) + geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y = min, colour = fill)) Strange - I'm not sure why that ever worked. When I adjust the code to the line below, it works again. But this time with two legend keys for group. Any idea how to display only one legend key for group? The ggplot-code aboved yielded only on legend key. ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group, fill = group)) + geom_ribbon() + geom_line(aes(y = max)) + geom_line(aes(y = min)) You can manually turn off one of the legends: sc - scale_colour_discrete() sc$legend - FALSE .last_plot + sc It's not very convenient though, so I'll think about how to do this automatically. The legends need to be more intelligent about only displaying the minimum necessary. Hadley __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend issue with ggplot2
Thanks Hadley, I've been struggling with this all afternoon. But now it's working again. Since I'm using it in a script, the few extra lines don't bother me that much. 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 [EMAIL PROTECTED] 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: hadley wickham [mailto:[EMAIL PROTECTED] Verzonden: maandag 3 september 2007 15:15 Aan: ONKELINX, Thierry CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] Legend issue with ggplot2 On 9/3/07, ONKELINX, Thierry [EMAIL PROTECTED] wrote: Dear useRs, I'm struggling with the new version of ggplot2. In the previous version I did something like this. But now this yield an error (object fill not found). library(ggplot2) dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10)) dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group] dummy$min - dummy$y - 5 dummy$max - dummy$y + 5 ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) + geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y = min, colour = fill)) Strange - I'm not sure why that ever worked. When I adjust the code to the line below, it works again. But this time with two legend keys for group. Any idea how to display only one legend key for group? The ggplot-code aboved yielded only on legend key. ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group, fill = group)) + geom_ribbon() + geom_line(aes(y = max)) + geom_line(aes(y = min)) You can manually turn off one of the legends: sc - scale_colour_discrete() sc$legend - FALSE .last_plot + sc It's not very convenient though, so I'll think about how to do this automatically. The legends need to be more intelligent about only displaying the minimum necessary. Hadley __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend issue with ggplot2
Yes - all this stuff is currently rather undocumented. Hopefully that will change in the near future! Hadley On 9/3/07, ONKELINX, Thierry [EMAIL PROTECTED] wrote: Thanks Hadley, I've been struggling with this all afternoon. But now it's working again. Since I'm using it in a script, the few extra lines don't bother me that much. 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 [EMAIL PROTECTED] 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: hadley wickham [mailto:[EMAIL PROTECTED] Verzonden: maandag 3 september 2007 15:15 Aan: ONKELINX, Thierry CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] Legend issue with ggplot2 On 9/3/07, ONKELINX, Thierry [EMAIL PROTECTED] wrote: Dear useRs, I'm struggling with the new version of ggplot2. In the previous version I did something like this. But now this yield an error (object fill not found). library(ggplot2) dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10)) dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group] dummy$min - dummy$y - 5 dummy$max - dummy$y + 5 ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) + geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y = min, colour = fill)) Strange - I'm not sure why that ever worked. When I adjust the code to the line below, it works again. But this time with two legend keys for group. Any idea how to display only one legend key for group? The ggplot-code aboved yielded only on legend key. ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group, fill = group)) + geom_ribbon() + geom_line(aes(y = max)) + geom_line(aes(y = min)) You can manually turn off one of the legends: sc - scale_colour_discrete() sc$legend - FALSE .last_plot + sc It's not very convenient though, so I'll think about how to do this automatically. The legends need to be more intelligent about only displaying the minimum necessary. Hadley -- http://had.co.nz/ __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Legend on graph
Hi Akki, Then you may need to increase y-axis scale by ylim=c(min,max) Cheers Nguyen On 8/12/07, akki [EMAIL PROTECTED] wrote: Hi, I have a problem when I want to put a legend on the graph. I do: legend(topright, names(o), cex=0.9, col=plot_colors,lty=1:5, bty=n) but the legend is writen into the graph (graphs' top but into the graph), because I have values on this position. How can I write the legend on top the graph without the legend writes on graph's values. 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend on graph
You can get the legend outside the plot region by 1. First changing the clipping region via par(xpd = TRUE) ; (or xpd=NA). see ?par 2. Specifying x and y coodinates for legend placement outside the limits of the plot region. This allows you to include a legend without adding a bunch of useless whitespace to the plot region; or to add a grid to the plot without interfering with the legend. Bert Gunter Genentech Nonclinical Statistics -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nguyen Dinh Nguyen Sent: Monday, August 13, 2007 3:42 PM To: [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Subject: [R] Legend on graph Hi Akki, Then you may need to increase y-axis scale by ylim=c(min,max) Cheers Nguyen On 8/12/07, akki [EMAIL PROTECTED] wrote: Hi, I have a problem when I want to put a legend on the graph. I do: legend(topright, names(o), cex=0.9, col=plot_colors,lty=1:5, bty=n) but the legend is writen into the graph (graphs' top but into the graph), because I have values on this position. How can I write the legend on top the graph without the legend writes on graph's values. 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 and provide commented, minimal, self-contained, reproducible code.
[R] Legend on graph
Hi, I have a problem when I want to put a legend on the graph. I do: legend(topright, names(o), cex=0.9, col=plot_colors,lty=1:5, bty=n) but the legend is writen into the graph (graphs' top but into the graph), because I have values on this position. How can I write the legend on top the graph without the legend writes on graph's values. Thanks. [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend on graph
If you are asking to have the values plotted on top of the legend, then you can do the following: plot(x, y, type='n', ...) # create plot, but don't plot legend('topright', ...) lines(x,y) # now plot the data If you want it outside the plot, check the archives for several examples. On 8/12/07, akki [EMAIL PROTECTED] wrote: Hi, I have a problem when I want to put a legend on the graph. I do: legend(topright, names(o), cex=0.9, col=plot_colors,lty=1:5, bty=n) but the legend is writen into the graph (graphs' top but into the graph), because I have values on this position. How can I write the legend on top the graph without the legend writes on graph's values. Thanks. [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend()
Hi Sir How can I use legend() outside th e plot. Please guid in this regard. Thanks -- AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend()
On Tue, 2007-07-31 at 10:21 -0700, amna khan wrote: Hi Sir How can I use legend() outside th e plot. Please guid in this regard. Thanks Create a plot, specifying outer margins to make space for the legend. Then move the legend to the open region. # Set 'xpd' to NA so that the legend is not clipped # at the plot region, which it is by default par(xpd = NA) # Make some room at the right hand side par(oma = c(0, 0, 0, 10)) # Do the plot plot(1:5) # Do the legend and use 'inset' to move the legend to # the right hand outer margin legend(topright, legend = 1:5, inset = c(-.4, .0)) You can adjust the outer margin settings and the 'inset' value as you may require to make room for the legend on the side required. See ?par and ?legend for more information. Another option would be to use layout() to create more than one plot region, perhaps adjusting the heights and/or widths of the plot regions, such that the data plot goes into one region and the legend into the other. See ?layout for more information. 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend and x,y cordinate values
See help(legend) and help(identify). Ajay Singh wrote: Hi, I have two problems in R. 1. I need 10 cdfs on a graph, the graph needs to have legend. Can you let me know how to get legend on the graph? 2. In ecdf plot, I need to know the x and y co-ordinates. I have to get corresponding y coordinate values to x coordinate value so that I could be able to know the particular percentile value to the x-coordinate value. Can you let me know how could I be able the corresponding values of x to the y coordinates? Thanking you, Looking forward to your kind response, Sincerely, Ajay. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend and x,y cordinate values
Hi, I have two problems in R. 1. I need 10 cdfs on a graph, the graph needs to have legend. Can you let me know how to get legend on the graph? 2. In ecdf plot, I need to know the x and y co-ordinates. I have to get corresponding y coordinate values to x coordinate value so that I could be able to know the particular percentile value to the x-coordinate value. Can you let me know how could I be able the corresponding values of x to the y coordinates? Thanking you, Looking forward to your kind response, Sincerely, Ajay. -- Ajay Singh Research Scientist, SOM, IIT-Bombay, Powai, MUMBAI-400076, MH (INDIA). __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend and lend (line end style)
Dear R-users, would you know a nice way to use the command lend in the legend? The following code gives you a really simple example and a inefficient workaround. Thanks in advance for any suggestion. Best, Giancarlo plot(c(1,1), lwd=15, lend=2, t=l) lines(c(0.8, 0.8), lwd=15, lend=1, col=2, lty=3) legend(topright, legend=c(bla, bla1), col=1:2, lty=c(1,3), lwd=15, cex=3) plot(c(1,1), lwd=15, lend=2, t=l) lines(c(0.8, 0.8), lwd=15, lend=1, col=2, lty=3) lege - legend(topright, legend=c(bla, bla1), col=1:2, pch=c(15,15), lty=0, cex=3, pt.cex=2.5, bty=n) points(lege$rect$left,lege$text$y[1], pch=15, cex=2.5, col=1) points(lege$rect$left+0.03,lege$text$y[1], pch=15, cex=2.5, col=1) points(lege$rect$left+0.05,lege$text$y[1], pch=15, cex=2.5, col=1) points(lege$rect$left,lege$text$y[2], pch=15, cex=2.5, col=2) === Camarda Carlo Giovanni PhD-Student Max Planck Institute for Demographic Research Konrad-Zuse-Strasse 1 18057 Rostock, Germany Tel: +49 (0)381 2081 172 Fax: +49 (0)381 2081 472 [EMAIL PROTECTED] === -- This mail has been sent through the MPI for Demographic Rese...{{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 and provide commented, minimal, self-contained, reproducible code.
[R] legend + expression
Dear all; A simple? question. I'm having a problem with a math expression in the legend of a plot and I haven't found the way to get this to work, so any help will be appreciate. Basically I want to include in the plot is the R-squared and its numerical value, so I tried this: R2c-0.82879 # R-squared of calibration model plot(1:10,1:10) legend(topleft, legend=c(expression(R[c]^2==format(R2c,nsmall=2 Thanks for any hint PM __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend + expression
what about legend(topleft, legend = bquote( R[c]2 == .(format(R2c,nsmall=2)) ) ) HTH, Peter __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend + expression
On Fri, 2007-06-08 at 17:27 -0400, Pedro Mardones wrote: Dear all; A simple? question. I'm having a problem with a math expression in the legend of a plot and I haven't found the way to get this to work, so any help will be appreciate. Basically I want to include in the plot is the R-squared and its numerical value, so I tried this: R2c-0.82879 # R-squared of calibration model plot(1:10,1:10) legend(topleft, legend=c(expression(R[c]^2==format(R2c,nsmall=2 Thanks for any hint PM Try this: R2c - 0.82879 plot(1:10,1:10) R2c.2 - sprintf(%.2f, R2c) legend(topleft, legend = bquote(R[c]^2 == .(R2c.2))) See ?bquote and if you search the list archives, there are more complex examples of using 'plotmath' in legends. Note also that 'nsmall' in format() does not fix the number of digits after the decimal: format(0.82879, nsmall = 2) [1] 0.82879 See ?formatC and ?sprintf for better options. 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend outside plotting area
Judith, Haven't tried it in anger myself, but two things suggest themselves. The first is to use the lattice package, which seems to draw keys (autokey option) outside the plot region by default. Look at the last couple of examples in ?xyplot. May save a lot of hassle... In classical R graphics, have you tried plotting everything explicitly inside a plot region with margins at zero? For example: plot.new() par(mar=c(0,0,0,0)) plot.window(xlim=c(-2,11), ylim=c(-3,13)) points(1:10,1:10, pch=1) points(1:10,10:1, pch=19) par(srt=90) text(x=-2, y=5, y-axis, pos=1, offset=0.5) par(srt=0) text(c(5,5), c(13,-1), labels=c(Title,x-axis), pos=1, offset=0.7, cex=c(1.5,1)) rect(-0.2,-0.2, 11.2,11.2) axis(side=1, at=0:10, pos=-0.2) axis(side=2, at=0:10, pos=-0.2) legend(x=5, y=-2, xjust=0.5, pch=c(1,19), legend=c(Type 1, Type 19), ncol=2) All very tedious, but it works. Also, fiddling around with things like pretty() on the data can automate most of the above positional choices if you're so inclined. And legend(..., plot=F) returns the legend size and coordinates if you want to fine-tune the location. Steve E [EMAIL PROTECTED] 23/05/2007 13:14:54 Quoting Judith Flores [EMAIL PROTECTED]: Hi, I have been trying many of the suggested options to place a legend outside plotting area, including something like this: par(xpd=T, oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) But the aspect of the four plots gets compromised when I change the margin settings. I cannot use mtext because I need to use colors for the text. I tried layout, but wouldn't let me include the legend, only plots. I would appreciate very much some more help. Regards, J *** This email and any attachments are confidential. Any use, co...{{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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend outside plotting area
Quoting Judith Flores [EMAIL PROTECTED]: Hi, I have been trying many of the suggested options to place a legend outside plotting area, including something like this: par(xpd=T, oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) But the aspect of the four plots gets compromised when I change the margin settings. I cannot use mtext because I need to use colors for the text. I tried layout, but wouldn't let me include the legend, only plots. I would appreciate very much some more help. Regards, J you can use 'mtext' with colors... mtext(whatever, col=blue...) -- Dr. Jose I. de las Heras Email: [EMAIL PROTECTED] The Wellcome Trust Centre for Cell BiologyPhone: +44 (0)131 6513374 Institute for Cell Molecular BiologyFax: +44 (0)131 6507360 Swann Building, Mayfield Road University of Edinburgh Edinburgh EH9 3JR UK __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Legend outside plotting area
Hi, I have been trying many of the suggested options to place a legend outside plotting area, including something like this: par(xpd=T, oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) But the aspect of the four plots gets compromised when I change the margin settings. I cannot use mtext because I need to use colors for the text. I tried layout, but wouldn't let me include the legend, only plots. I would appreciate very much some more help. Regards, J Pinpoint customers who are looking for what you sell. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend outside plotting area
RSiteSearch(legend outside plot) will bring you many links to the discussions of this question. layout perfectly allows everything. typical sequence looks like this This divides the device region by two parts one below another: layout(matrix(c(1,2),byrow=TRUE), heights=[blah-blah-blah], [some other arguments]) Then we plot on the first part: plot( ... ) lines ( ... ) points ( ... ) grid( ... ) [ whatever you want on the plotting area] Then we finish plotting on the first part of the layout matrix and come to the next, legend part. The only thing to do is placing the legend in the top left corner. plot.new(); plot.window(c(0,1), c(0,1)); legend(0,1, [ legend text ] ) Judith Flores wrote: Hi, I have been trying many of the suggested options to place a legend outside plotting area, including something like this: par(xpd=T, oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) But the aspect of the four plots gets compromised when I change the margin settings. I cannot use mtext because I need to use colors for the text. I tried layout, but wouldn't let me include the legend, only plots. I would appreciate very much some more help. Regards, J -- View this message in context: http://www.nabble.com/Legend-outside-plotting-area-tf3794564.html#a10735956 Sent from the R help mailing list archive at Nabble.com. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend outside plotting area
Judith, you might try split.screen() and related functions, see ?screen. Example: split.screen(c(1,2)) # 1 row, 2 columns split.screen(c(2,2), screen = 1) # split left column into 2x2 for(i in 3:6) { screen(i); plot(1:10) } screen(2) plot(1, type=n, axes=F, ann=F) # empty plot legend(center, pch=1, legend=Data) Regards, Carsten Hi, I have been trying many of the suggested options to place a legend outside plotting area, including something like this: par(xpd=T, oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) But the aspect of the four plots gets compromised when I change the margin settings. I cannot use mtext because I need to use colors for the text. I tried layout, but wouldn't let me include the legend, only plots. I would appreciate very much some more help. Regards, J __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend with mixed boxes and lines (not both)
Hi, I seem to be unable to get a mixed legend that has lines *or* polygons (not both). For example: ppi - seq(0,2*pi,length.out=21)[-21] frame() plot.window(ylim=c(-5,5),xlim=c(-5,5),asp=1) polygon(cos(ppi)*4+rnorm(20,sd=.2),sin(ppi)*4+rnorm(20,sd=.2), col=green,border=FALSE) polygon(cos(ppi)*2+rnorm(20,sd=.1),sin(ppi)*2+rnorm(20,sd=.1), col=blue,border=FALSE) abline(0,2,col=red) legend(topleft,legend=c(out,in,line),bty=n, fill=c(green,blue,NA),col=c(NA,NA,red), lwd=c(NA,NA,1)) I'm really guessing the behaviour in the legend() call, by setting fill to NA for the item, etc. I also tried fill=c(green,blue,FALSE), but that didn't go over too well either. I also tried adding merge=TRUE, but that just puts the line into the box. I also tried using box.lwd=c(1,1,0), but that also did not work Is there either a way to do this or a clean workaround? Thanks in advance. +mt __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend with mixed boxes and lines (not both)
On Mon, 2007-05-14 at 18:13 -0700, Michael Toews wrote: Hi, I seem to be unable to get a mixed legend that has lines *or* polygons (not both). For example: ppi - seq(0,2*pi,length.out=21)[-21] frame() plot.window(ylim=c(-5,5),xlim=c(-5,5),asp=1) polygon(cos(ppi)*4+rnorm(20,sd=.2),sin(ppi)*4+rnorm(20,sd=.2), col=green,border=FALSE) polygon(cos(ppi)*2+rnorm(20,sd=.1),sin(ppi)*2+rnorm(20,sd=.1), col=blue,border=FALSE) abline(0,2,col=red) legend(topleft,legend=c(out,in,line),bty=n, fill=c(green,blue,NA),col=c(NA,NA,red), lwd=c(NA,NA,1)) I'm really guessing the behaviour in the legend() call, by setting fill to NA for the item, etc. I also tried fill=c(green,blue,FALSE), but that didn't go over too well either. I also tried adding merge=TRUE, but that just puts the line into the box. I also tried using box.lwd=c(1,1,0), but that also did not work Is there either a way to do this or a clean workaround? Thanks in advance. +mt Is this what you want? ppi - seq(0, 2 * pi, length.out = 21)[-21] plot(c(-5, 5), c(-5, 5), xaxs = i, yaxs = i, type = n, axes = FALSE, ann = FALSE, asp=1) polygon(cos(ppi) * 4 + rnorm(20, sd = .2), sin(ppi) * 4 + rnorm(20, sd = .2), col = green, border = FALSE) polygon(cos(ppi) * 2 + rnorm(20, sd = .1), sin(ppi) * 2 + rnorm(20, sd= .1), col = blue, border = FALSE) abline(0, 2, col = red) legend(topleft, legend = c(out, in, line), bty = n, col = c(green, blue, red), lty = c(0, 0, 1), lwd = c(0, 0, 1), pch = c(22, 22, NA), pt.bg = c(green, blue, NA), pt.cex = 2) Instead of using 'fill', set the points explicitly and then define the point backgrounds, line types, etc. to get the desired result. See ?par for line type information. BTW, some strategically placed spaces would help with code readability. 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend with density and fill
Hi, I am trying to make a legend with four symbols as follows 1.white box 2.black box 3.clear box (same as background) 4.clear box with shading lines but the shading lines arent showing... here is my code. par(bg=lightyellow) barplot(c(seq(1,6,1))) legend(8.5,0.3, bty=o, legend=c(young,old,male,female), col=black,cex=1.5, fill=c(white,dark grey,0,0),density=c(NA,NA,0,100),angle=45) any suggestions much appreciated, Thanks, Simon. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend with density and fill
Hi Simon, Try fill=c(white,dark grey,black,black), density=c(NA,NA,25,75), etc Cheers Andrew On Sat, Mar 17, 2007 at 12:36:19PM +, Simon Pickett wrote: Hi, I am trying to make a legend with four symbols as follows 1.white box 2.black box 3.clear box (same as background) 4.clear box with shading lines but the shading lines arent showing... here is my code. par(bg=lightyellow) barplot(c(seq(1,6,1))) legend(8.5,0.3, bty=o, legend=c(young,old,male,female), col=black,cex=1.5, fill=c(white,dark grey,0,0),density=c(NA,NA,0,100),angle=45) any suggestions much appreciated, Thanks, Simon. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ 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 and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend question
? par it is the xpd you're looking for. x - seq(-pi, pi, len = 65) par(xpd=TRUE) plot(x, sin(x), type=l, col = 2,xpd=NA) legend(x = 0, y = -1.5, legend text, pch = 1, xjust = 0.5) --- Jenny Barnes [EMAIL PROTECTED] wrote: Hi folks, Do you mind if I ask a related question that I have been having trouble with - how do you put the legend outside of the plot area (to the bottom of the area - below the x-axis title)? Could anybody show me using the example given below: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) Thank you, I've not been able to do this simple bit of programming and it is very frustrating not to be able to add a simple key. Best Wishes, Jenny Hi Emili, Even though you are calling your horizontal coordinate y, and vertical coordinate z, the first and second arguments to legend(), namely x and y, should be the horizontal and vertical coordinates, respectively; and they are given in user coordinates (e.g., legend()'s x should be between 1960 and 1975 and legend()'s y should be between 1 and 4). If you want to use normalized coordinates (i.e. 0 to 1), you can scale as in this example: legend(x = par(usr)[1] + diff(par(usr)[1:2])*normalizedCoordX, y = par(usr)[3] + diff(par(usr)[3:4])*normalizedCoordY, ...) where normalizedCoordX and Y go from 0 to 1 (see ?par, par(usr) returns vector of c(xmin,xmax,ymin,ymax) of user coordinates on a plot) You can alternatively use legend(x = topleft,...) or bottomright, and so on to place your legend. If you want to add your legend outside of the plot, you should consider increasing the margins using the 'mar' argument in par(), and also setting par(xpd=TRUE) (so stuff can show up outside of the plotting region). Best regards, ST y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) within the data limits of your x and y) --- Emili Tortosa-Ausina [EMAIL PROTECTED] wrote: Hi to all, I'm sorry for posting this question, I am sure I am missing something important but after reading the documentation I cannot find where the problem is. I want to add a legend to a figure. If I use a simple example drawn from the R Reference Manual such as, for instance: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then everything works just fine. However, if I use other data such as, for instance: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then the legend is not shown. Any hints? Thanks in advance, Emili __ 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 and provide commented, minimal, self-contained, reproducible code. Food fight? Enjoy some healthy debate __ 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 and provide commented, minimal, self-contained, reproducible code. - End Forwarded Message - ~~ Jennifer Barnes PhD student: long range drought prediction Climate Extremes Group Department of Space and Climate Physics University College London Holmbury St Mary Dorking, Surrey, RH5 6NT Tel: 01483 204149 Mob: 07916 139187 Web: http://climate.mssl.ucl.ac.uk __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend question
Hi to all, I'm sorry for posting this question, I am sure I am missing something important but after reading the documentation I cannot find where the problem is. I want to add a legend to a figure. If I use a simple example drawn from the R Reference Manual such as, for instance: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then everything works just fine. However, if I use other data such as, for instance: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then the legend is not shown. Any hints? Thanks in advance, Emili __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend question
On Wed, 28 Feb 2007 17:06:18 +0100 Emili Tortosa-Ausina [EMAIL PROTECTED] wrote: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) your x and y are outside the plotting area. try using a different set, or better still use locator() to specify x, y interactively. hth, ranjan __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend question
Hi Emili, Even though you are calling your horizontal coordinate y, and vertical coordinate z, the first and second arguments to legend(), namely x and y, should be the horizontal and vertical coordinates, respectively; and they are given in user coordinates (e.g., legend()'s x should be between 1960 and 1975 and legend()'s y should be between 1 and 4). If you want to use normalized coordinates (i.e. 0 to 1), you can scale as in this example: legend(x = par(usr)[1] + diff(par(usr)[1:2])*normalizedCoordX, y = par(usr)[3] + diff(par(usr)[3:4])*normalizedCoordY, ...) where normalizedCoordX and Y go from 0 to 1 (see ?par, par(usr) returns vector of c(xmin,xmax,ymin,ymax) of user coordinates on a plot) You can alternatively use legend(x = topleft,...) or bottomright, and so on to place your legend. If you want to add your legend outside of the plot, you should consider increasing the margins using the 'mar' argument in par(), and also setting par(xpd=TRUE) (so stuff can show up outside of the plotting region). Best regards, ST y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) within the data limits of your x and y) --- Emili Tortosa-Ausina [EMAIL PROTECTED] wrote: Hi to all, I'm sorry for posting this question, I am sure I am missing something important but after reading the documentation I cannot find where the problem is. I want to add a legend to a figure. If I use a simple example drawn from the R Reference Manual such as, for instance: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then everything works just fine. However, if I use other data such as, for instance: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then the legend is not shown. Any hints? Thanks in advance, Emili __ 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 and provide commented, minimal, self-contained, reproducible code. Food fight? Enjoy some healthy debate __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend question
try: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(topleft, legend text, pch = 1, xjust = 0.5) On 2/28/07, Emili Tortosa-Ausina [EMAIL PROTECTED] wrote: Hi to all, I'm sorry for posting this question, I am sure I am missing something important but after reading the documentation I cannot find where the problem is. I want to add a legend to a figure. If I use a simple example drawn from the R Reference Manual such as, for instance: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then everything works just fine. However, if I use other data such as, for instance: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then the legend is not shown. Any hints? Thanks in advance, Emili __ 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 and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend question
Hi folks, Do you mind if I ask a related question that I have been having trouble with - how do you put the legend outside of the plot area (to the bottom of the area - below the x-axis title)? Could anybody show me using the example given below: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) Thank you, I've not been able to do this simple bit of programming and it is very frustrating not to be able to add a simple key. Best Wishes, Jenny Hi Emili, Even though you are calling your horizontal coordinate y, and vertical coordinate z, the first and second arguments to legend(), namely x and y, should be the horizontal and vertical coordinates, respectively; and they are given in user coordinates (e.g., legend()'s x should be between 1960 and 1975 and legend()'s y should be between 1 and 4). If you want to use normalized coordinates (i.e. 0 to 1), you can scale as in this example: legend(x = par(usr)[1] + diff(par(usr)[1:2])*normalizedCoordX, y = par(usr)[3] + diff(par(usr)[3:4])*normalizedCoordY, ...) where normalizedCoordX and Y go from 0 to 1 (see ?par, par(usr) returns vector of c(xmin,xmax,ymin,ymax) of user coordinates on a plot) You can alternatively use legend(x = topleft,...) or bottomright, and so on to place your legend. If you want to add your legend outside of the plot, you should consider increasing the margins using the 'mar' argument in par(), and also setting par(xpd=TRUE) (so stuff can show up outside of the plotting region). Best regards, ST y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) within the data limits of your x and y) --- Emili Tortosa-Ausina [EMAIL PROTECTED] wrote: Hi to all, I'm sorry for posting this question, I am sure I am missing something important but after reading the documentation I cannot find where the problem is. I want to add a legend to a figure. If I use a simple example drawn from the R Reference Manual such as, for instance: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then everything works just fine. However, if I use other data such as, for instance: y-c(1960, 1965, 1970, 1975) z-c(1, 2, 3, 4) plot(y, z, type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) then the legend is not shown. Any hints? Thanks in advance, Emili __ 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 and provide commented, minimal, self-contained, reproducible code. Food fight? Enjoy some healthy debate __ 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 and provide commented, minimal, self-contained, reproducible code. - End Forwarded Message - ~~ Jennifer Barnes PhD student: long range drought prediction Climate Extremes Group Department of Space and Climate Physics University College London Holmbury St Mary Dorking, Surrey, RH5 6NT Tel: 01483 204149 Mob: 07916 139187 Web: http://climate.mssl.ucl.ac.uk __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend question
On Wed, 28 Feb 2007 16:52:05 + (GMT), Jenny Barnes [EMAIL PROTECTED] wrote: Hi folks, Do you mind if I ask a related question that I have been having trouble with - how do you put the legend outside of the plot area (to the bottom of the area - below the x-axis title)? Could anybody show me using the example given below: x - seq(-pi, pi, len = 65) plot(x, sin(x), type=l, col = 2) legend(x = -3, y = .9, legend text, pch = 1, xjust = 0.5) Thank you, I've not been able to do this simple bit of programming and it is very frustrating not to be able to add a simple key. Have a look at ?par and argument 'inset' in ?legend itself. Here's one way: x - seq(-pi, pi, len=65) par(mar=c(par(mar)[1] + 2, par(mar)[-1])) plot(x, sin(x), type=l, col=2) par(xpd=TRUE) legend(bottom, legend text, pch=1, inset=-0.3) -- Seb __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot [Broadcast]
On 2/14/07, Albert Vilella [EMAIL PROTECTED] wrote: I am defining the legend using trellis.par.set (not sure if correctly), and space does not seem to do the trick. auto-key (here commented) places it to the top... You want 'auto.key = list(space = right)'. Deepayan a = rep(c(alfa,beta,gamma,alfa,beta,gamma),100) b = rnorm(600) input=data.frame(a,b) densityplot(~(input$b), groups=input$a, plot.points=FALSE, # auto.key=TRUE, space = left, trellis.par.set(superpose.line = list( col = rep( c(yellow,green,red,blue,orange,pink,lightblue,black,brown), 3) , lwd=3, lty = rep( c(1,2,3), each = 9) ) ) ) On 2/14/07, Wiener, Matthew [EMAIL PROTECTED] wrote: From the documentation for xyplot (referred to from densityplot): The position of the key can be controlled in either of two possible ways. If a component called space is present, the key is positioned outside the plot region, in one of the four sides, determined by the value of space, which can be one of top, bottom, left and right. Hope this helps, Matt Wiener -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Albert Vilella Sent: Wednesday, February 14, 2007 8:46 AM To: R-help@stat.math.ethz.ch Subject: Re: [R] legend in lattice densityplot [Broadcast] How can I place the legend to the left or right of the densityplot? By default, it goes at the top, and as it is a rather long list, the density plot only uses half the space of the whole graphic... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Me too on Windows XP. Its probably just a bug or unimplemented feature in the SVG driver. Write to the maintainer of that package For a workaround generate fig output and then convert it to svg using whatever fig editor or converter you have. (On my windows system I use the free fig2dev converter although it inserted a DOCTYPE statement into the generated SVG file that IE7 did not recognize but once I manually deleted that it displayed ok in IE7.) # after producing file01.fig run # fig2dev -L svg file01.fig file01.svg # or use some other fig to svg converter or editor xfig(file = /file01.fig, onefile = TRUE) library(lattice) set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 dev.off() On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f
Re: [R] legend in lattice densityplot
How can I place the legend to the left or right of the densityplot? By default, it goes at the top, and as it is a rather long list, the density plot only uses half the space of the whole graphic... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Me too on Windows XP. Its probably just a bug or unimplemented feature in the SVG driver. Write to the maintainer of that package For a workaround generate fig output and then convert it to svg using whatever fig editor or converter you have. (On my windows system I use the free fig2dev converter although it inserted a DOCTYPE statement into the generated SVG file that IE7 did not recognize but once I manually deleted that it displayed ok in IE7.) # after producing file01.fig run # fig2dev -L svg file01.fig file01.svg # or use some other fig to svg converter or editor xfig(file = /file01.fig, onefile = TRUE) library(lattice) set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 dev.off() On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot .
Re: [R] legend in lattice densityplot [Broadcast]
From the documentation for xyplot (referred to from densityplot): The position of the key can be controlled in either of two possible ways. If a component called space is present, the key is positioned outside the plot region, in one of the four sides, determined by the value of space, which can be one of top, bottom, left and right. Hope this helps, Matt Wiener -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Albert Vilella Sent: Wednesday, February 14, 2007 8:46 AM To: R-help@stat.math.ethz.ch Subject: Re: [R] legend in lattice densityplot [Broadcast] How can I place the legend to the left or right of the densityplot? By default, it goes at the top, and as it is a rather long list, the density plot only uses half the space of the whole graphic... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Me too on Windows XP. Its probably just a bug or unimplemented feature in the SVG driver. Write to the maintainer of that package For a workaround generate fig output and then convert it to svg using whatever fig editor or converter you have. (On my windows system I use the free fig2dev converter although it inserted a DOCTYPE statement into the generated SVG file that IE7 did not recognize but once I manually deleted that it displayed ok in IE7.) # after producing file01.fig run # fig2dev -L svg file01.fig file01.svg # or use some other fig to svg converter or editor xfig(file = /file01.fig, onefile = TRUE) library(lattice) set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 dev.off() On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6
Re: [R] legend in lattice densityplot [Broadcast]
I am defining the legend using trellis.par.set (not sure if correctly), and space does not seem to do the trick. auto-key (here commented) places it to the top... a = rep(c(alfa,beta,gamma,alfa,beta,gamma),100) b = rnorm(600) input=data.frame(a,b) densityplot(~(input$b), groups=input$a, plot.points=FALSE, # auto.key=TRUE, space = left, trellis.par.set(superpose.line = list( col = rep( c(yellow,green,red,blue,orange,pink,lightblue,black,brown), 3) , lwd=3, lty = rep( c(1,2,3), each = 9) ) ) ) On 2/14/07, Wiener, Matthew [EMAIL PROTECTED] wrote: From the documentation for xyplot (referred to from densityplot): The position of the key can be controlled in either of two possible ways. If a component called space is present, the key is positioned outside the plot region, in one of the four sides, determined by the value of space, which can be one of top, bottom, left and right. Hope this helps, Matt Wiener -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Albert Vilella Sent: Wednesday, February 14, 2007 8:46 AM To: R-help@stat.math.ethz.ch Subject: Re: [R] legend in lattice densityplot [Broadcast] How can I place the legend to the left or right of the densityplot? By default, it goes at the top, and as it is a rather long list, the density plot only uses half the space of the whole graphic... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Me too on Windows XP. Its probably just a bug or unimplemented feature in the SVG driver. Write to the maintainer of that package For a workaround generate fig output and then convert it to svg using whatever fig editor or converter you have. (On my windows system I use the free fig2dev converter although it inserted a DOCTYPE statement into the generated SVG file that IE7 did not recognize but once I manually deleted that it displayed ok in IE7.) # after producing file01.fig run # fig2dev -L svg file01.fig file01.svg # or use some other fig to svg converter or editor xfig(file = /file01.fig, onefile = TRUE) library(lattice) set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 dev.off() On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis
Re: [R] legend in lattice densityplot [Broadcast]
I use key= instead. Much more flexible. I set the parameters in trellis.par.set for the plot and then take these settings in key to get them in the legend. space= is part of the key= settings. As in this (to stick with your example): library(lattice) lg - c(alfa,beta,gamma) a - rep(lg, 200) b - rnorm(600) input - data.frame(a,b) densityplot(~(input$b), groups = input$a, plot.points = FALSE, trellis.par.set(superpose.line = list( col = rep( c(yellow,green,red,blue,orange,pink,lightblue,black,brown) ,3), lwd = rep( 3, 27), lty = rep( c(1,2,3), each = 9) ) ), key = list(space=left, lines=list( col = trellis.par.get()$superpose.line$col[1:3], lwd = trellis.par.get()$superpose.line$lwd[1:3], lty = trellis.par.get()$superpose.line$lty[1:3] ), text=list(lg)) ) Hope this helps. Rene -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Albert Vilella Sent: Wednesday, February 14, 2007 6:50 AM To: Wiener, Matthew Cc: R-help@stat.math.ethz.ch Subject: Re: [R] legend in lattice densityplot [Broadcast] I am defining the legend using trellis.par.set (not sure if correctly), and space does not seem to do the trick. auto-key (here commented) places it to the top... a = rep(c(alfa,beta,gamma,alfa,beta,gamma),100) b = rnorm(600) input=data.frame(a,b) densityplot(~(input$b), groups=input$a, plot.points=FALSE, # auto.key=TRUE, space = left, trellis.par.set(superpose.line = list( col = rep( c(yellow,green,red,blue,orange,pink,lightblue,black,brown) , 3) , lwd=3, lty = rep( c(1,2,3), each = 9) ) ) ) On 2/14/07, Wiener, Matthew [EMAIL PROTECTED] wrote: From the documentation for xyplot (referred to from densityplot): The position of the key can be controlled in either of two possible ways. If a component called space is present, the key is positioned outside the plot region, in one of the four sides, determined by the value of space, which can be one of top, bottom, left and right. Hope this helps, Matt Wiener -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Albert Vilella Sent: Wednesday, February 14, 2007 8:46 AM To: R-help@stat.math.ethz.ch Subject: Re: [R] legend in lattice densityplot [Broadcast] How can I place the legend to the left or right of the densityplot? By default, it goes at the top, and as it is a rather long list, the density plot only uses half the space of the whole graphic... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Me too on Windows XP. Its probably just a bug or unimplemented feature in the SVG driver. Write to the maintainer of that package For a workaround generate fig output and then convert it to svg using whatever fig editor or converter you have. (On my windows system I use the free fig2dev converter although it inserted a DOCTYPE statement into the generated SVG file that IE7 did not recognize but once I manually deleted that it displayed ok in IE7.) # after producing file01.fig run # fig2dev -L svg file01.fig file01.svg # or use some other fig to svg converter or editor xfig(file = /file01.fig, onefile = TRUE) library(lattice) set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 dev.off() On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely
[R] legend font
Hi, I'd like to make the text in my legends italic, but I can't figure out how to do so. font=3 doesn't work. Googling brings up the possibility of expression(italic()), which produces italics, but I can't get this to work with my label data, which is a vector of strings: legend(locator(1), legend = levels(factor(label.vector)), col = plotting.colours, pch =plotsym.bw, cex = 0.7 ) How can I do this? -- Regards, Tyler Smith __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend font
On 2/14/2007 1:32 PM, Tyler Smith wrote: Hi, I'd like to make the text in my legends italic, but I can't figure out how to do so. font=3 doesn't work. Googling brings up the possibility of expression(italic()), which produces italics, but I can't get this to work with my label data, which is a vector of strings: legend(locator(1), legend = levels(factor(label.vector)), col = plotting.colours, pch =plotsym.bw, cex = 0.7 ) How can I do this? This should work: plot(1,1) savefont - par(font=3) legend(topright, legend=c('Label 1', 'Label 2'), pch=1:2) par(savefont) Duncan Murdoch __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend font
On Wed, Feb 14, 2007 at 02:40:47PM -0500, Duncan Murdoch wrote: On 2/14/2007 1:32 PM, Tyler Smith wrote: Hi, I'd like to make the text in my legends italic, ... How can I do this? This should work: plot(1,1) savefont - par(font=3) legend(topright, legend=c('Label 1', 'Label 2'), pch=1:2) par(savefont) Thanks! I don't understand it yet, but it does indeed work. -- Regards, Tyler Smith __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend font
On 2/14/2007 3:12 PM, Tyler Smith wrote: On Wed, Feb 14, 2007 at 02:40:47PM -0500, Duncan Murdoch wrote: On 2/14/2007 1:32 PM, Tyler Smith wrote: Hi, I'd like to make the text in my legends italic, ... How can I do this? This should work: plot(1,1) savefont - par(font=3) legend(topright, legend=c('Label 1', 'Label 2'), pch=1:2) par(savefont) Thanks! I don't understand it yet, but it does indeed work. The idea is that the first par() command changes the default font for everything. (The legend() function doesn't pass any font request down to the graphics system, it just uses the default font.) It also returns the old font setting and I saved it in savefont. The second par() call restores the old font setting. Duncan Murdoch __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Legend function
Dear Sir Lengend add a bix containing plot discription in the existing plot. Is there any function which decribe the lines in a plot outside the existing plot? I have also a question related to following statement. In this statement * is used for plot discription. If we have plotted type=o of plot then what pch is to be used. legend(30,3.5, c(Fuel,Smoothed Fuel), pch=* , lty=c(0,1)) Please Help in this regard AMINA SHAHZADI Department of Statistics GC University Lahore, Pakistan. Email: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend/plotmath/substitute problem
Dear R Experts, I am trying to produce a legend for a series of plots which are generated in a loop. The legend is supposed to look like this: 2000: gamma=1.8 where gamma is replaced by the greek letter and both the year and the value of gamma are stored in variables. Everything works fine as long as I have only one data series: year = 2001 g = 1.9 plot(1) legend('top', legend=substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)) ) My problem starts, when I want to put more than one series of data in the plot and accordingly need one legend row per data series: year1 = 2001 year2 = 2005 g1 = 1.9 g2 = 1.7 plot(1) legend('top', legend=c( substitute(paste(year, ': ', gamma, '=', g), list(year=year1, g=g1)), substitute(paste(year, ': ', gamma, '=', g), list(year=year2, g=g2)) ) ) This obviously does not produce the desired result. Apparently, I am not generating a list of expressions, as intended. So I thought, maybe R uses a variety of the recycling rule here and tried: year = c(2001, 2005) g = c(1.9, 1.7) plot(1) legend('top', legend=list( substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)), ) ) No succes, either... I have read and re-read the documentation for legend, expression, substitute and plotmath but can't figure it out. Even drinking a cup of tea prepared from fine-cut man page printouts didn't lead to satori. I'm probably missing something simple. Any hints are highly appreciated. Thanks Philipp -- Dr. Philipp PagelTel. +49-8161-71 2131 Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186 Technical University of Munich 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend/plotmath/substitute problem
On 12/14/2006 5:05 PM, Philipp Pagel wrote: Dear R Experts, I am trying to produce a legend for a series of plots which are generated in a loop. The legend is supposed to look like this: 2000: gamma=1.8 where gamma is replaced by the greek letter and both the year and the value of gamma are stored in variables. Everything works fine as long as I have only one data series: year = 2001 g = 1.9 plot(1) legend('top', legend=substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)) ) My problem starts, when I want to put more than one series of data in the plot and accordingly need one legend row per data series: year1 = 2001 year2 = 2005 g1 = 1.9 g2 = 1.7 plot(1) legend('top', legend=c( substitute(paste(year, ': ', gamma, '=', g), list(year=year1, g=g1)), substitute(paste(year, ': ', gamma, '=', g), list(year=year2, g=g2)) ) ) This obviously does not produce the desired result. Apparently, I am not generating a list of expressions, as intended. So I thought, maybe R uses a variety of the recycling rule here and tried: The problem is that legend wants an expression, but substitute() isn't returning one, it's returning a call, and c(call1,call2) produces a list of two calls, not an expression holding two calls. So the following would work, but there might be something more elegant: year1 = 2001 year2 = 2005 g1 = 1.9 g2 = 1.7 plot(1) legend('top', legend=c( as.expression(substitute(paste(year, ': ', gamma, '=', g), list(year=year1, g=g1))), as.expression(substitute(paste(year, ': ', gamma, '=', g), list(year=year2, g=g2))) ) ) Duncan Murdoch year = c(2001, 2005) g = c(1.9, 1.7) plot(1) legend('top', legend=list( substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)), ) ) No succes, either... I have read and re-read the documentation for legend, expression, substitute and plotmath but can't figure it out. Even drinking a cup of tea prepared from fine-cut man page printouts didn't lead to satori. I'm probably missing something simple. Any hints are highly appreciated. Thanks Philipp __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend/plotmath/substitute problem
On Thu, Dec 14, 2006 at 06:25:49PM -0500, Duncan Murdoch wrote: On 12/14/2006 5:05 PM, Philipp Pagel wrote: My problem starts, when I want to put more than one series of data in the plot and accordingly need one legend row per data series: year1 = 2001 year2 = 2005 g1 = 1.9 g2 = 1.7 plot(1) legend('top', legend=c( substitute(paste(year, ': ', gamma, '=', g), list(year=year1, g=g1)), substitute(paste(year, ': ', gamma, '=', g), list(year=year2, g=g2)) ) ) This obviously does not produce the desired result. Apparently, I am not generating a list of expressions, as intended. So I thought, maybe R uses a variety of the recycling rule here and tried: The problem is that legend wants an expression, but substitute() isn't returning one, it's returning a call, and c(call1,call2) produces a list of two calls, not an expression holding two calls. So the following would work, but there might be something more elegant: Thanks a lot! Learned something, again. cu Philipp -- Dr. Philipp PagelTel. +49-8161-71 2131 Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186 Technical University of Munich 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Albert Vilella wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? Yes. Using Gabor's suggestion of changing the trellis settings within the call to densityplot(), try something like this: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE, par.settings = list(superpose.line = list(col = c(Green, Red, Blue), lty=c(2,1,2 On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Me too on Windows XP. Its probably just a bug or unimplemented feature in the SVG driver. Write to the maintainer of that package For a workaround generate fig output and then convert it to svg using whatever fig editor or converter you have. (On my windows system I use the free fig2dev converter although it inserted a DOCTYPE statement into the generated SVG file that IE7 did not recognize but once I manually deleted that it displayed ok in IE7.) # after producing file01.fig run # fig2dev -L svg file01.fig file01.svg # or use some other fig to svg converter or editor xfig(file = /file01.fig, onefile = TRUE) library(lattice) set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 dev.off() On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Should it be a problem to print this dashed line plots as svgs? library(RSvgDevice) devSVG(file = /home/avilella/file01.svg, width = 20, height = 16, bg = white, fg = black, onefile=TRUE, xmlHeader=TRUE) densityplot(...) dev.off() I am getting all the lines as continuous, not dashed... On 11/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes by using the lty suboption of superpose.line. Here is a modification of the prior example to illustrate: We also use lwd as well in this example. set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2, lwd = c(1,1,1,1,2 On 11/30/06, Albert Vilella [EMAIL PROTECTED] wrote: Can I combine colors and line types? For example, would it be possible to have 5 colors per 2 types of lines (continuous and dashed)? On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010
[R] legend in lattice densityplot
Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Are this legend colors correlated to the plot? If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Try specifying it at the par.settings= level since that is where both the plot and the legend get it from: set.seed(1) DF - data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)), f = sample(c(A,B,C,D,E),300,replace=TRUE)) library(lattice) densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE, par.settings = list(superpose.line = list(col = heat.colors(5 On 11/29/06, Albert Vilella [EMAIL PROTECTED] wrote: Are this legend colors correlated to the plot? If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend in lattice densityplot
Albert Vilella wrote: Are this legend colors correlated to the plot? They are if you rely on the colors in trellis.par.get(superpose.line)$col If you want different colors you might use trellis.par.set() to temporarily change the colors: x - c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1)) f - rep(c(A,B,C), each=100) df - data.frame(x,f) library(lattice) oldpar - trellis.par.get(superpose.line)$col trellis.par.set(superpose.line = list(col = heat.colors(3))) densityplot(~ x, groups = f, data = df, plot.points=FALSE, auto.key=TRUE) trellis.par.set(superpose.line = list(col = oldpar)) If you don't require points or lines in the key, you also could do something like this: densityplot(~ x, groups = f, data = df, plot.points=FALSE, key = simpleKey(levels(df$f), lines=FALSE, points=FALSE, col=heat.colors(3)), col=heat.colors(3)) To use your own colors without changing the trellis settings and to get lines or points in the key, you probably need at least to use key = simpleKey() rather than the auto.key argument, and you may need to look into draw.key(). Other people on the list might know simpler approaches for using your own colors in this situation. If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland [EMAIL PROTECTED] wrote: Albert Vilella wrote: Hi, I have a densityplot like this: x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) f = sample(c(A,B,C,D,E),300,replace=TRUE) df=data.frame(x,f) library(lattice) attach(df) densityplot(~x, groups=f) And I want to add a legend with the colours for the factors. How can I do that? How can I not have the dots of the distribution at the bottom, or at least, make them occupy less vertical space? Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot . __ 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 and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (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 and provide commented, minimal, self-contained, reproducible code.
[R] legend positioning problems
Hello, I have several Barplots I want to plot. I also want to include a legend. Since my Barplots are very different I ve dicided to put the legend in the top left corner. Unfortunately, sometimes there is a part of a bar just below the legend. This makes it difficult to see the legend itself or the barplot. All I found out so far, is to make the backgroundcolor of the legend white or so, but I would couldn t see the bar anymore. Is there a way, to position the legend excel-like on the outside the plot on the side? or Is there a possibility to use sort of an alpha-factor to make the background white but slightly invisible so that there is a contrast? I hope you can help me out and thank you in advance! #Example: barplot(VADeaths) legend(topleft, c(1x, 2x, 3x, 4x, 5x), bg=white)) Markus Schweitzer - http://www.pokertips.tk __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend problems in lattice
Hi! Im sorry to bother you but I cant fix this. I use the lattice function levelplot and I want the colorkey at the bottom, how do I get it there? I have tried changing colorkey.space and changing in legend but I cant get it right, plz help btw I'd like to speceify strings to appear at the tick marks and also there I fail any thoughts? cheers Ernst __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend problems in lattice
Ernst O Ahlberg Helgee wrote: Hi! Im sorry to bother you but I cant fix this. I use the lattice function levelplot and I want the colorkey at the bottom, how do I get it there? I have tried changing colorkey.space and changing in legend but I cant get it right, plz help btw I'd like to speceify strings to appear at the tick marks and also there I fail any thoughts? cheers Ernst __ 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 and provide commented, minimal, self-contained, reproducible code. Hi, Ernst, Please read ?levelplot. Under the argument for colorkey you will see: colorkey: logical specifying whether a color key is to be drawn alongside the plot, or a list describing the color key. The list may contain the following components: 'space': location of the colorkey, can be one of 'left', 'right', 'top' and 'bottom'. Defaults to 'right'. So the answer to your first question is: levelplot(..., colorkey = list(space = bottom)) For your second question, use the scale argument. See ?xyplot for details. For example, levelplot(..., scale = list(x = list(at = 1:4, labels = letters[1:4]))) 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 and provide commented, minimal, self-contained, reproducible code.
[R] Legend box line thickness
I am making a plot and am merely trying to increase the line thickness, or width, of the box drawn around the legend. The help page on 'legend' was of no use. Does anyone have any ideas? [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Legend box line thickness
I am merely trying to increase the line thickness, or line width, of the box drawn around the legend in a plot I am constructing. The help page on 'legend' was of no use. Does anyone have an idea on how to do this? Please respond to [EMAIL PROTECTED] 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend box line thickness
On Mon, 2006-08-28 at 17:55 -0700, Phil Turk wrote: I am merely trying to increase the line thickness, or line width, of the box drawn around the legend in a plot I am constructing. The help page on 'legend' was of no use. Does anyone have an idea on how to do this? Please respond to [EMAIL PROTECTED] Thanks! There are two options. The easier one is not immediately evident from the help page and requires reviewing the R code for the legend function, which reveals that there is an internal function called rect2(), which is built on top of rect(). It is this function that draws the outer box. The help page for rect() shows that the line width argument 'lwd' in the function defaults to par(lwd). See ?par for more information. Thus using: par(lwd = SomethingGreaterThan1) before the call to legend will set the box to a wider line thickness. Be sure to set par(lwd = 1) before any other plot calls to return to the default setting. Second, the Value section of ?legend clearly indicates: Value A list with list components rect a list with components w, h positive numbers giving width and height of the legend's box. left, top x and y coordinates of upper left corner of the box. text a list with components x, y numeric vectors of length length(legend), giving the x and y coordinates of the legend's text(s). returned invisibly. Thus, expanding on the third example in ?legend: ## right-justifying a set of labels: thanks to Uwe Ligges x - 1:5; y1 - 1/x; y2 - 2/x plot(rep(x, 2), c(y1, y2), type=n, xlab=x, ylab=y) lines(x, y1); lines(x, y2, lty=2) # Key call here temp - legend(topright, legend = c( , ), text.width = strwidth(1,000,000), lty = 1:2, xjust = 1, yjust = 1, title = Line Types) text(temp$rect$left + temp$rect$w, temp$text$y, c(1,000, 1,000,000), pos=2) # Now do the legend box using a wide line: rect(temp$rect$left, temp$rect$top - temp$rect$h, temp$rect$left + temp$rect$w, temp$rect$top + temp$rect$h, lwd = 2) It would not seem unreasonable to add new arguments to legend(), perhaps calling them box.lwd and box.lty, which can then be passed to the rect2() internal function call for the box by modifying the existing call to: rect2(left, top, dx = w, dy = h, col = bg, density = NULL, lwd = box.lwd, lty = box.lty) 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend on trellis plot
Dear all I have two questions regarding trellis plots - which I hope you may be able to help me with. Is it possible to place the key in a trellis plot on the panel (instead of beside the panel)? This will cause the same key to be reproduced on each panel. Please see the plot below - here I placed the legend below the plot. I tried moving the key to the function statement, but it did not really work out the way I expected. One last thing, in the plot below I placed a horizontal line on the plot, is it possible to only have the horizontal line on the left panel (I remember that in S it was possible to state something like if(get(cell,fr=9)==2) in the function statement to include the line on only one of the panels)? All suggestions will highly appreciated. Br Henrik ### data - as.data.frame(cbind(rep(1:4,each=25), rep(1:2,each=50) ,rep(1:25,4), rnorm(100,0,1) )) names(data) - c(ID,DOSE,TIME,DV) xyplot(DV~TIME | DOSE, data=data, groups=ID, layout=c(2,1), key=list(space=bottom,border=TRUE,colums=2,text=list(c(ID1,ID2),col=c(1,4)), lines=list(type=o,pch=c(1,16),lty=c(1,2), col=c(1,4)), layout.heights=list(key.axis.padding=15)), panel = function(x,y,groups,...) { panel.superpose.2(x,y,groups,...,type=o,pch=c(1,16), lty=c(1,2), col=c(1,4), cex=0.8) panel.abline(h=0.301,col=5,lty=1,lwd=2) } ) ### [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] legend on trellis plot
1. Use the x, y and corner components to the key= list to specify the legend position, and 2. pass the panel.number in the panel function and test that as shown in the panel function below. Alternately you can place the horizontal line on afterwards using trellis.focus/trellis.unfocus as shown below. Read the material under key= and panel= in ?xyplot for more information on the key and panel arguments and read ?trellis.focus for more information on trellis.focus/trellis.unfocus. xyplot(DV~TIME | DOSE, data=data, groups=ID, layout=c(2,1), key=list(x=.1,y=.8,corner=c(0,0),border=TRUE,colums=2,text=list(c(ID1,ID2),col=c(1,4)), lines=list(type=o,pch=c(1,16),lty=c(1,2), col=c(1,4)), layout.heights=list(key.axis.padding=15)), panel = function(x,y,groups,...,panel.number) { panel.superpose.2(x,y,groups,...,type=o,pch=c(1,16), lty=c(1,2), col=c(1,4), cex=0.8) if (panel.number == 1) panel.abline(h=0.301,col=5,lty=1,lwd=2) } ) # add a red horizontal line only to panel 2, 1 trellis.focus(panel, 2, 1, highlight = FALSE) panel.abline(h=0.301,col=2,lty=1,lwd=2) trellis.unfocus() On 8/9/06, HKAG (Henrik Agersø) [EMAIL PROTECTED] wrote: Dear all I have two questions regarding trellis plots - which I hope you may be able to help me with. Is it possible to place the key in a trellis plot on the panel (instead of beside the panel)? This will cause the same key to be reproduced on each panel. Please see the plot below - here I placed the legend below the plot. I tried moving the key to the function statement, but it did not really work out the way I expected. One last thing, in the plot below I placed a horizontal line on the plot, is it possible to only have the horizontal line on the left panel (I remember that in S it was possible to state something like if(get(cell,fr=9)==2) in the function statement to include the line on only one of the panels)? All suggestions will highly appreciated. Br Henrik ### data - as.data.frame(cbind(rep(1:4,each=25), rep(1:2,each=50) ,rep(1:25,4), rnorm(100,0,1) )) names(data) - c(ID,DOSE,TIME,DV) xyplot(DV~TIME | DOSE, data=data, groups=ID, layout=c(2,1), key=list(space=bottom,border=TRUE,colums=2,text=list(c(ID1,ID2),col=c(1,4)), lines=list(type=o,pch=c(1,16),lty=c(1,2), col=c(1,4)), layout.heights=list(key.axis.padding=15)), panel = function(x,y,groups,...) { panel.superpose.2(x,y,groups,...,type=o,pch=c(1,16), lty=c(1,2), col=c(1,4), cex=0.8) panel.abline(h=0.301,col=5,lty=1,lwd=2) } ) ### [[alternative HTML version deleted]] __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] legend outside plotting area
Hi, I would like to place a legend outside a plotting area. Could anybody give me a hint how this is done? Cheers, Georg __ 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] legend outside plotting area
see http://finzi.psych.upenn.edu/R/Rhelp02a/archive/68585.html Georg Otto wrote: Hi, I would like to place a legend outside a plotting area. Could anybody give me a hint how this is done? Cheers, Georg __ 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 confidentiality notice: The information contained in this e-mail is confidential and...{{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] legend with filled boxes AND lines
Dear all, Is there a straightforward way to create a legend box that has both filled boxes and lines? So far I have built around this problem by creating two legends (with bty = n) and manually drawing a box around both (but this is cumbersome, because I have to check upon the y coordinates of the legends every time). If I do something like legend( ...,c(X1,X2, mean), fill = c(red, blue, 0), lty = (0,0,2)) , I cannot get rid of the unfilled box or change the color of the fill box border (from its default color black), and I end up with two filled boxes and an empty, black-lined box plus the line as a legend for the third argument mean. This trick therefore only works if I define black as the bg color for the complete legend box (because it masks the empty box from the fill argument). So, if there is a command to modify the color of the fill box border line (not the legend box border line), this would help me, too (still not ideal, though...). Thanks, Florian __ Florian Koller GfK Fernsehforschung GmbH Research Consulting Development Nordwestring 101 D-90319 Nürnberg Fon +49 (0)911 395-3554 Fax +49 (0)911 395-4130 www.gfk.de / www.gfk.com _ Diese E-Mail (ggf. nebst Anhang) enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind, oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet. This e-mail (and any attachment/s) contains confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. __ 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] legend with filled boxes AND lines
Did you try legend(.., lty=..., fill=..., merge = TRUE) ? In an example I just tried, this allowed to give filled boxes *and* lines. Please give a reproducible example of what you did -- maybe by modifying one of the many example(legend) examples. Martin Maechler, ETH Zurich florian == florian koller [EMAIL PROTECTED] on Mon, 3 Jul 2006 13:40:33 +0200 writes: florian Dear all, florian Is there a straightforward way to create a legend florian box that has both filled boxes and lines? So far I florian have built around this problem by creating two florian legends (with bty = n) and manually drawing a box florian around both (but this is cumbersome, because I have florian to check upon the y coordinates of the legends florian every time). florian If I do something like legend( ...,c(X1,X2, florian mean), fill = c(red, blue, 0), lty = (0,0,2)) florian , I cannot get rid of the unfilled box or change florian the color of the fill box border (from its default florian color black), and I end up with two filled boxes florian and an empty, black-lined box plus the line as a florian legend for the third argument mean. This trick florian therefore only works if I define black as the bg florian color for the complete legend box (because it masks florian the empty box from the fill argument). So, if there florian is a command to modify the color of the fill box florian border line (not the legend box border line), this florian would help me, too (still not ideal, though...). florian Thanks, florian Florian florian __ florian Florian Koller florian GfK Fernsehforschung GmbH florian Research Consulting Development florian Nordwestring 101 florian D-90319 Nürnberg florian Fon +49 (0)911 395-3554 florian Fax +49 (0)911 395-4130 florian www.gfk.de / www.gfk.com florian _ florian Diese E-Mail (ggf. nebst Anhang) enthält vertrauliche und/oder rechtlich florian geschützte Informationen. Wenn Sie nicht der richtige Adressat sind, oder florian diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den florian Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die florian unbefugte Weitergabe dieser Mail ist nicht gestattet. florian This e-mail (and any attachment/s) contains confidential and/or privileged florian information. If you are not the intended recipient (or have received this florian e-mail in error) please notify the sender immediately and destroy this florian e-mail. Any unauthorised copying, disclosure or distribution of the florian material in this e-mail is strictly forbidden. florian __ florian R-help@stat.math.ethz.ch mailing list florian https://stat.ethz.ch/mailman/listinfo/r-help florian 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] legend title in effects plot
Could someone tell how I can change/remove the legend title in a (multiline) effect plot? Thanks V In general, how is one supposed to find out answers to such questions? It is virtually impossible to keep track of what graphical parameters are passed on to which low level function and which don't. Every funciton calls legend labels a different name (title, key, legend.lab, etc.). I tried the help pages of par,plot,effect,legend, without an effect :-) __ 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] Legend titles in log plots broken? (ver. 2.2.1)
I forgot to mention: if you want to use the patch without installing a new version of R, it's available by sourcing the file https://svn.r-project.org/R/branches/R-2-3-patches/src/library/graphics/R/legend.R It was just a one character change: Index: legend.R === --- legend.R(revision 38022) +++ legend.R(revision 38033) @@ -226,7 +226,7 @@ xt - xt + x.intersp * xchar if(plot) { - if (!is.null(title)) text(left + w/2, top - ymax, labels = title, + if (!is.null(title)) text2(left + w/2, top - ymax, labels = title, adj = c(0.5, 0), cex = cex, col = text.col) text2(xt, yt, labels = legend, adj = adj, cex = cex, col = text.col) Duncan Murdoch Rob Steele wrote: Legend titles work in linear plots: curve(1/x, xlim = c(0, 1)) legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') But when you change to a log plot on either dimension things get screwy: curve(1/x, xlim = c(0, 1), log = 'y') legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') If you save the value legend() returns you can look at it and see that it's messed up: l - legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') l $rect $rect$w [1] 0.2349272 $rect$h [1] 0.2727899 $rect$left [1] 0.7618728 $rect$top [1] 1.9936 $text $text$x [1] 0.9188374 $text$y [1] 1.81174 R.Version() $platform [1] i686-redhat-linux-gnu $arch [1] i686 $os [1] linux-gnu $system [1] i686, linux-gnu $status [1] $major [1] 2 $minor [1] 2.1 $year [1] 2005 $month [1] 12 $day [1] 20 $svn rev [1] 36812 $language [1] R __ 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] Legend titles in log plots broken? (ver. 2.2.1)
Legend titles work in linear plots: curve(1/x, xlim = c(0, 1)) legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') But when you change to a log plot on either dimension things get screwy: curve(1/x, xlim = c(0, 1), log = 'y') legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') If you save the value legend() returns you can look at it and see that it's messed up: l - legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') l $rect $rect$w [1] 0.2349272 $rect$h [1] 0.2727899 $rect$left [1] 0.7618728 $rect$top [1] 1.9936 $text $text$x [1] 0.9188374 $text$y [1] 1.81174 R.Version() $platform [1] i686-redhat-linux-gnu $arch [1] i686 $os [1] linux-gnu $system [1] i686, linux-gnu $status [1] $major [1] 2 $minor [1] 2.1 $year [1] 2005 $month [1] 12 $day [1] 20 $svn rev [1] 36812 $language [1] R __ 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] Legend titles in log plots broken? (ver. 2.2.1)
Rob Steele wrote: Legend titles work in linear plots: curve(1/x, xlim = c(0, 1)) legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') But when you change to a log plot on either dimension things get screwy: curve(1/x, xlim = c(0, 1), log = 'y') legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') If you save the value legend() returns you can look at it and see that it's messed up: l - legend(x = 'topright', inset = 0.04, legend = '1/x', lty = 1, title = 'Legend Title') I don't think this is the problem. It's simply a little bug in legend() that puts the title in the wrong place when a log scale is used. I'll fix it. Duncan Murdoch l $rect $rect$w [1] 0.2349272 $rect$h [1] 0.2727899 $rect$left [1] 0.7618728 $rect$top [1] 1.9936 $text $text$x [1] 0.9188374 $text$y [1] 1.81174 R.Version() $platform [1] i686-redhat-linux-gnu $arch [1] i686 $os [1] linux-gnu $system [1] i686, linux-gnu $status [1] $major [1] 2 $minor [1] 2.1 $year [1] 2005 $month [1] 12 $day [1] 20 $svn rev [1] 36812 $language [1] R __ 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] Legend in the outer margin
Dear Rs I have a 3x3 multiple plot. I would like to have a overall legend in the outer right margin. From the help archive, I found that it can be done by setting par(xpd=NA). However, I couldn't find the correct values for x and y co-ordinates for the legend. Please find the code snippet below: par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(1,2,2,4),cex.main=1.1) *postscript(*file=epsfile,onefile=FALSE,horizontal=TRUE*)* /* some plotting */ par(xpd=NA) legend(legend=c(2h-opt Exact,1-shift Exact,2p-opt Exact), lty=c(solid,dashed,dotdash),lwd=c(2,2,2),col=c(red,green,black), bty=n,cex=0.8) Thanks in advance Prasanna [[alternative HTML version deleted]] __ 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] Legend in the outer margin
Prasanna wrote: Dear Rs I have a 3x3 multiple plot. I would like to have a overall legend in the outer right margin. From the help archive, I found that it can be done by setting par(xpd=NA). However, I couldn't find the correct values for x and y co-ordinates for the legend. Please find the code snippet below: par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(1,2,2,4),cex.main=1.1) *postscript(*file=epsfile,onefile=FALSE,horizontal=TRUE*)* /* some plotting */ par(xpd=NA) You get the user coordinates of the plotting region by par(usr) Now simply make the legend right of that plotting region, e.g. with x corrdinates at par(usr)[2] + epsilon and y coordinates at mean(par(usr)[3:4]) Uwe Ligges legend(legend=c(2h-opt Exact,1-shift Exact,2p-opt Exact), lty=c(solid,dashed,dotdash),lwd=c(2,2,2),col=c(red,green,black), bty=n,cex=0.8) Thanks in advance Prasanna [[alternative HTML version deleted]] __ 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] Legend in the outer margin
Uwe Ligges ligges at statistik.uni-dortmund.de writes: You get the user coordinates of the plotting region by par(usr) Now simply make the legend right of that plotting region, e.g. with x corrdinates at par(usr)[2] + epsilon and y coordinates at mean(par(usr)[3:4]) I always found it ugly that this depends on the last plotted figure in an array, but I wanted to position my legend independent of it at an absolute position in device space. What's the best way to achieve this? par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(5,2,5,10),cex.main=1.1) n=7 # Legend should be positioned independent of n for (i in 1:n){ plot(rnorm(20),ylim=c(-3,3)) } # ... just the idea reset_to_01_coordinates() par(xpd=NA) leg = legend(0.9,0.5, # Should be seen as absolute in 0/1 coords c(2h-opt Exact,1-shift Exact,2p-opt Exact), lty=c(solid,dashed,dotdash),lwd=c(2,2,2), col=c(red,green,black), bty=n,cex=0.8) Dieter __ 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] Legend in the outer margin
The cnvrt.coords function in the TeachingDemos package may be of help. Here is an example of possible use (just change the .9 and .7 to where ever on the page you want the legend): par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(1,2,2,4),cex.main=1.1) for (i in 1:9){ x - runif(25,1,10) y - 3+ i*x + rnorm(25) plot(x,y) } par(xpd=NA) tmp - cnvrt.coords(.9,.7, 'tdev')$usr legend(tmp,legend=c(2h-opt Exact,1-shift Exact,2p-opt Exact), lty=c(solid,dashed,dotdash),lwd=c(2,2,2),col=c(red,green,blac k), bty=n,cex=0.8) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dieter Menne Sent: Monday, April 10, 2006 7:40 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] Legend in the outer margin Uwe Ligges ligges at statistik.uni-dortmund.de writes: You get the user coordinates of the plotting region by par(usr) Now simply make the legend right of that plotting region, e.g. with x corrdinates at par(usr)[2] + epsilon and y coordinates at mean(par(usr)[3:4]) I always found it ugly that this depends on the last plotted figure in an array, but I wanted to position my legend independent of it at an absolute position in device space. What's the best way to achieve this? par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(5,2,5,10),cex.main=1.1) n=7 # Legend should be positioned independent of n for (i in 1:n){ plot(rnorm(20),ylim=c(-3,3)) } # ... just the idea reset_to_01_coordinates() par(xpd=NA) leg = legend(0.9,0.5, # Should be seen as absolute in 0/1 coords c(2h-opt Exact,1-shift Exact,2p-opt Exact), lty=c(solid,dashed,dotdash),lwd=c(2,2,2), col=c(red,green,black), bty=n,cex=0.8) Dieter __ 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] legend in bubble plots made with symbols()
Hi, I have read about the use of symbols() to draw circles of different sizes, but I have not been able to find out how to add a legend to such a graph, legend that would display some specific sizes and their meaning. Before finding the symbols function in Paul Murrell's book, I had rolled by own function where the variable I want to use to control circle size was actually used to control cex. I was able to draw a legend afterward. Symbols seems a bit simpler and I wanted to see if it would be better than my own function. But without legend it is less useful. However I'm sure there is a way which I'm not aware of to draw a legend for a plot drawn with symbols()... Thanks in advance, Denis Chabot __ 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] legend in bubble plots made with symbols()
Denis Chabot wrote: Hi, I have read about the use of symbols() to draw circles of different sizes, but I have not been able to find out how to add a legend to such a graph, legend that would display some specific sizes and their meaning. Before finding the symbols function in Paul Murrell's book, I had rolled by own function where the variable I want to use to control circle size was actually used to control cex. I was able to draw a legend afterward. Symbols seems a bit simpler and I wanted to see if it would be better than my own function. But without legend it is less useful. However I'm sure there is a way which I'm not aware of to draw a legend for a plot drawn with symbols()... Thanks in advance, Denis Chabot library(Hmisc) ?xYplot See the size argument and the use of the skey function that is generated by xYplot. Frank __ 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 -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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] legend in bubble plots made with symbols()
On Sat, 18 Mar 2006, Denis Chabot wrote: Hi, I have read about the use of symbols() to draw circles of different sizes, but I have not been able to find out how to add a legend to such a graph, legend that would display some specific sizes and their meaning. Before finding the symbols function in Paul Murrell's book, I had rolled by own function where the variable I want to use to control circle size was actually used to control cex. I was able to draw a legend afterward. Symbols seems a bit simpler and I wanted to see if it would be better than my own function. But without legend it is less useful. However I'm sure there is a way which I'm not aware of to draw a legend for a plot drawn with symbols()... There is a recent paper in JSS by Susumu Tanimura, Chusi Kuroiwa, and Tsutomu Mizota, including some legend code: http://www.jstatsoft.org/ Volume 15, 2006, Issue 5 Thanks in advance, Denis Chabot __ 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 -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ 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] Legend in a HeatMap
List, Is it possible to add a color legend to a heatmap , similar to the one in levelplot and filled.contour plot. The legend will represent the colors used in the heatmap along with values for each color range. Can this be done? Please help. Thanks, Svakki. __ 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] Legend Outside Plot Dimension
Hi I think you need to use par(xpd=TRUE). Try to search archives as similar question was answered few days ago. HTH Petr On 19 Jan 2006 at 12:19, Abd Rahman Kassim wrote: From: Abd Rahman Kassim [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Date sent: Thu, 19 Jan 2006 12:19:30 -0800 Subject:[R] Legend Outside Plot Dimension Dear All, I'm trying to attach a legend outside the plot (Inside plot OK), but failed. Any help is very much appreciated. Thanks. Abd. Rahman Kassim, PhD Forest Management Ecology Program Forestry Conservation Division Forest Research Institute Malaysia Kepong 52109 Selangor MALAYSIA * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * [[alternative HTML version deleted]] __ 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 Petr Pikal [EMAIL PROTECTED] __ 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] Legend Outside Plot Dimension
Dear Peter, Thanks for your promt response. Abd. Rahman - Original Message - From: Petr Pikal [EMAIL PROTECTED] To: Abd Rahman Kassim [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Sent: Thursday, January 19, 2006 12:11 AM Subject: Re: [R] Legend Outside Plot Dimension Hi I think you need to use par(xpd=TRUE). Try to search archives as similar question was answered few days ago. HTH Petr On 19 Jan 2006 at 12:19, Abd Rahman Kassim wrote: From: Abd Rahman Kassim [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Date sent: Thu, 19 Jan 2006 12:19:30 -0800 Subject:[R] Legend Outside Plot Dimension Dear All, I'm trying to attach a legend outside the plot (Inside plot OK), but failed. Any help is very much appreciated. Thanks. Abd. Rahman Kassim, PhD Forest Management Ecology Program Forestry Conservation Division Forest Research Institute Malaysia Kepong 52109 Selangor MALAYSIA * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * [[alternative HTML version deleted]] __ 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 Petr Pikal [EMAIL PROTECTED] * Outgoing mail is certified Virus Free. Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * __ 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] Legend Outside Plot Dimension
Dear All, I'm trying to attach a legend outside the plot (Inside plot OK), but failed. Any help is very much appreciated. Thanks. Abd. Rahman Kassim, PhD Forest Management Ecology Program Forestry Conservation Division Forest Research Institute Malaysia Kepong 52109 Selangor MALAYSIA * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * [[alternative HTML version deleted]] __ 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] Legend Outside Plot Dimension
use xpd argument in par(), as follows: ?par par(xpd=T, mar=par()$mar+c(0,0,0,4)) plot(1,1) legend(1.5,1,point,pch=1) Abd Rahman Kassim a écrit : Dear All, I'm trying to attach a legend outside the plot (Inside plot OK), but failed. Any help is very much appreciated. Thanks. Abd. Rahman Kassim, PhD Forest Management Ecology Program Forestry Conservation Division Forest Research Institute Malaysia Kepong 52109 Selangor MALAYSIA * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * [[alternative HTML version deleted]] __ 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] Legend Outside Plot Dimension
Dear Jacques, Thanks for the promt response. Abd. Rahman - Original Message - From: Jacques VESLOT [EMAIL PROTECTED] To: Abd Rahman Kassim [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, January 18, 2006 9:15 PM Subject: Re: [R] Legend Outside Plot Dimension use xpd argument in par(), as follows: ?par par(xpd=T, mar=par()$mar+c(0,0,0,4)) plot(1,1) legend(1.5,1,point,pch=1) Abd Rahman Kassim a écrit : Dear All, I'm trying to attach a legend outside the plot (Inside plot OK), but failed. Any help is very much appreciated. Thanks. Abd. Rahman Kassim, PhD Forest Management Ecology Program Forestry Conservation Division Forest Research Institute Malaysia Kepong 52109 Selangor MALAYSIA * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * [[alternative HTML version deleted]] __ 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 * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. * * Checked by TrendMicro Interscan Messaging Security. For any enquiries, please contact FRIM IT Department. __ 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] Legend
I use the following to plot two graphs over each other and then insert a legend, but the two items in the legend both come up the same colour x = seq(0,30,0.01) plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs for Data and\n Fitted PDF over Entire 15 Weeks') lines(x, pexp(x,0.415694806),col=red) legend(x=5,y=0.2 , legend=c(Data Set,Fitted PDF),col=c(black,red)) Many thanks Mark Miller __ 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] Legend
Mark Miller wrote: I use the following to plot two graphs over each other and then insert a legend, but the two items in the legend both come up the same colour x = seq(0,30,0.01) plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs for Data and\n Fitted PDF over Entire 15 Weeks') lines(x, pexp(x,0.415694806),col=red) legend(x=5,y=0.2 , legend=c(Data Set,Fitted PDF),col=c(black,red)) Many thanks Mark Miller Hi, Mark, You want to use text.col in legend instead of col: set.seed(1) z - rexp(30, 0.415694806) x - seq(0, 30, 0.1) plot(ecdf(z), do.point = FALSE) lines(x, pexp(x, 0.415694806), col=red) legend(x = 5, y = 0.2, legend = c(Data Set, Fitted PDF), text.col = c(black, red)) --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
Re: [R] Legend
And you want to have different colored lines but black texts, try legend(x = 5, y = 0.2, legend = c(Data Set, Fitted PDF), col = c(black, red), lty=1) The advantage of this is that you can use dotted (lty option) or lines with different weights (lwd option). Regards, Adai On Sun, 2005-11-13 at 06:46 -0600, Sundar Dorai-Raj wrote: Mark Miller wrote: I use the following to plot two graphs over each other and then insert a legend, but the two items in the legend both come up the same colour x = seq(0,30,0.01) plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs for Data and\n Fitted PDF over Entire 15 Weeks') lines(x, pexp(x,0.415694806),col=red) legend(x=5,y=0.2 , legend=c(Data Set,Fitted PDF),col=c(black,red)) Many thanks Mark Miller Hi, Mark, You want to use text.col in legend instead of col: set.seed(1) z - rexp(30, 0.415694806) x - seq(0, 30, 0.1) plot(ecdf(z), do.point = FALSE) lines(x, pexp(x, 0.415694806), col=red) legend(x = 5, y = 0.2, legend = c(Data Set, Fitted PDF), text.col = c(black, red)) --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-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] Legend out of Plot Region
Hi, Could someone tell me how to place a legend outside the plot region? Thanks, Mike __ 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] Legend out of Plot Region
Le 24.09.2005 20:22, Michel Friesenhahn a écrit : Hi, Could someone tell me how to place a legend outside the plot region? Thanks, Mike Hi Mike, Take a look at : R par(xpd=NA) -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.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] legend
I color some area grey with polygon() (with a red border) and then I want to have the dashed red border in the legend as well. How do I manage it? And I want to mix (latex) expressions with text in my legend. Just execute my lines below and you know want I mean. Or pass by at http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online. Thomas bm - function(n=500, from=0, to=1) { x=seq(from=from,to=to,length=n) BM-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n cbind(x,BM) } gbm - function(bm,S0=1,sigma=0.1,mu=1) { gbm=S0 for (t in 2:length(bm[,1])) { gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2]) } cbind(bm[,1],gbm) } set.seed(9826064) cs=c(dark green, steelblue, red, yellow) #png(filename = GBM.png, width=1600, height=1200, pointsize = 12) par(bg=lightgrey) x=seq(from=0,to=1,length=500) plot(x=x, y=exp(0.7*x), type=n, xlab=Zeit, ylab=, ylim=c(1,3.5)) polygon(x=c(x,rev(x)), y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col=grey, border=cs[3], lty=dashed) lines(x=x,y=exp(0.7*x), type=l, lwd=3, col=cs[1]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4]) title(main=Geometrische Brownsche Bewegung,cex.main=2.5) legend(x=0,y=3.5,legend=c(exp(0.7x),mu=0.7, sigma=0.4,mu=0.7, sigma=0.2,mu=0.7, sigma=0.1,Standardabweichung für sigma=0.2),lwd=c(4,4,4,4,12),col=c(cs,grey),bg=transparent,cex=1.15) #dev.off() __ 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] legend
Thomas Steiner wrote: I color some area grey with polygon() (with a red border) and then I want to have the dashed red border in the legend as well. How do I manage it? And I want to mix (latex) expressions with text in my legend. Both points are not that easy to solve, hence I'd like to suggest to write your own little function that generates the legend. Starting at the upper left, calculating the stringheight, painting the (party very special) symbols, and adding the text line by line seems to be the most easiest solution here (which is not that nice, though. Uwe Ligges Just execute my lines below and you know want I mean. Or pass by at http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online. Thomas bm - function(n=500, from=0, to=1) { x=seq(from=from,to=to,length=n) BM-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n cbind(x,BM) } gbm - function(bm,S0=1,sigma=0.1,mu=1) { gbm=S0 for (t in 2:length(bm[,1])) { gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2]) } cbind(bm[,1],gbm) } set.seed(9826064) cs=c(dark green, steelblue, red, yellow) #png(filename = GBM.png, width=1600, height=1200, pointsize = 12) par(bg=lightgrey) x=seq(from=0,to=1,length=500) plot(x=x, y=exp(0.7*x), type=n, xlab=Zeit, ylab=, ylim=c(1,3.5)) polygon(x=c(x,rev(x)), y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col=grey, border=cs[3], lty=dashed) lines(x=x,y=exp(0.7*x), type=l, lwd=3, col=cs[1]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4]) title(main=Geometrische Brownsche Bewegung,cex.main=2.5) legend(x=0,y=3.5,legend=c(exp(0.7x),mu=0.7, sigma=0.4,mu=0.7, sigma=0.2,mu=0.7, sigma=0.1,Standardabweichung für sigma=0.2),lwd=c(4,4,4,4,12),col=c(cs,grey),bg=transparent,cex=1.15) #dev.off() __ 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] legend
Hi Uwe Ligges wrote: Thomas Steiner wrote: I color some area grey with polygon() (with a red border) and then I want to have the dashed red border in the legend as well. How do I manage it? And I want to mix (latex) expressions with text in my legend. Both points are not that easy to solve, hence I'd like to suggest to write your own little function that generates the legend. Starting at the upper left, calculating the stringheight, painting the (party very special) symbols, and adding the text line by line seems to be the most easiest solution here (which is not that nice, though. I don't think it's too bad. For example, try replacing the original ... legend(x=0,y=3.5,legend=c(exp(0.7x),mu=0.7, sigma=0.4,mu=0.7, sigma=0.2,mu=0.7, sigma=0.1,Standardabweichung für sigma=0.2),lwd=c(4,4,4,4,12),col=c(cs,grey),bg=transparent,cex=1.15) ... with ... # Use grid and gridBase so you've got some sensible # coordinate systems to work within library(grid) library(gridBase) # Align a grid viewport with the plotting region vps - baseViewports() pushViewport(vps$inner, vps$figure, vps$plot) # Define labels and colours # Labels are mathematical expressions labels - expression(exp(0.7x), list(mu == 0.7,sigma == 0.4), list(mu == 0.7,sigma == 0.2), list(mu == 0.7, sigma == 0.1), paste(Standardabweichung für ,sigma == 0.2)) cols - cs # Draw each legend item on its own line # Top line 1cm in from top-left corner for (i in 1:5) { x - unit(1, cm) y - unit(1, npc) - unit(1, cm) - unit(i, lines) if (i 5) { grid.lines(unit.c(x, unit(2, cm)), y + unit(0.5, lines), gp=gpar(col=cols[i], lwd=3)) } else { grid.rect(x, y, width=unit(1, cm), height=unit(1, lines), gp=gpar(fill=grey, col=cs[3], lty=dashed), just=c(left, bottom)) } grid.text(labels[i], x + unit(1.5, cm), y, just=c(left, bottom)) } # clean up popViewport(3) ... that's a bit of typing, but if you need to do more than one, it would go inside a function with labels and cols as arguments (and '5' replaced by 'length(labels)') without too much trouble. (In this case, you could also pretty easily just do the main plot using grid and avoid having to use gridBase.) Paul Just execute my lines below and you know want I mean. Or pass by at http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online. Thomas bm - function(n=500, from=0, to=1) { x=seq(from=from,to=to,length=n) BM-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n cbind(x,BM) } gbm - function(bm,S0=1,sigma=0.1,mu=1) { gbm=S0 for (t in 2:length(bm[,1])) { gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2]) } cbind(bm[,1],gbm) } set.seed(9826064) cs=c(dark green, steelblue, red, yellow) #png(filename = GBM.png, width=1600, height=1200, pointsize = 12) par(bg=lightgrey) x=seq(from=0,to=1,length=500) plot(x=x, y=exp(0.7*x), type=n, xlab=Zeit, ylab=, ylim=c(1,3.5)) polygon(x=c(x,rev(x)), y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col=grey, border=cs[3], lty=dashed) lines(x=x,y=exp(0.7*x), type=l, lwd=3, col=cs[1]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3]) lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4]) title(main=Geometrische Brownsche Bewegung,cex.main=2.5) legend(x=0,y=3.5,legend=c(exp(0.7x),mu=0.7, sigma=0.4,mu=0.7, sigma=0.2,mu=0.7, sigma=0.1,Standardabweichung für sigma=0.2),lwd=c(4,4,4,4,12),col=c(cs,grey),bg=transparent,cex=1.15) #dev.off() __ 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 -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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] legend as a subtitle
Very little space is available in one of my plots for the legend. I would like to lift it out of the main plot area and present it in the subtitle area. Would appreciate any help that I can get. Ravi Vishnu This message is meant for the addressee only and may contain confidential and legally privileged information. Any unauthorised review, use, copying, storage, disclosure or distribution of this e- mail and any attachments is strictly prohibited. If you are not the named recipient or have otherwise received this communication in error, please destroy this message from your system and kindly notify the sender by e-mail. Thank you for your co-operation. [[alternative HTML version deleted]] __ 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] legend as a subtitle
[EMAIL PROTECTED] wrote: Very little space is available in one of my plots for the legend. I would like to lift it out of the main plot area and present it in the subtitle area. Would appreciate any help that I can get. Look at the following code and read the corresponding help pages: plot(1:10, xlab=) ## clipping to device region rather than plot region: par(xpd=NA) legend(mean(par(usr)[1:2]), 0, legend=nonsense, xjust=0.5) Uwe Ligges Ravi Vishnu This message is meant for the addressee only and may contain confidential and legally privileged information. Any unauthorised review, use, copying, storage, disclosure or distribution of this e- mail and any attachments is strictly prohibited. If you are not the named recipient or have otherwise received this communication in error, please destroy this message from your system and kindly notify the sender by e-mail. Thank you for your co-operation. [[alternative HTML version deleted]] __ 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] legend(): how to put variable in subscript?
Aleksey Naumov [EMAIL PROTECTED] writes: Dear List, I would like to plot a simple legend with two math expressions, e.g. plot(0) legend(1, 0.5, expression(sigma[i], sigma[j])) The difficulty is that i and j should be variables rather than strings i and j. In other words I'd like to do something like: i = A j = B legend(1, 0.5, expression(sigma[i], sigma[j])) and have A and B as the actual subscripts. I can substitute the variable in the expression e.g.: legend(1, 0.5, substitute(sigma[i], list(i='A', j='B'))) legend(1, 0.5, bquote(sigma[.(i)])) however, this gives me just one of the two entries in the legend. I cannot figure out how to include both sigmas in the legend. What would be the best way to do something like this? Thank you for your ideas or suggestions. Ick. One of those cases that suggests that our current substitute mechanisms don't quite cut it... However, try i - A; j - B e - bquote(expression(sigma[.(i)],sigma[.(j)])) plot(0) legend(1,.5,eval(e)) legend(1,-.5,e) # for comparison Thing is, substitute(expression(),...) returns a call to the expression constructor, rather than the expression itself, so you need the eval(). -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] legend(): how to put variable in subscript?
Dear List, I would like to plot a simple legend with two math expressions, e.g. plot(0) legend(1, 0.5, expression(sigma[i], sigma[j])) The difficulty is that i and j should be variables rather than strings i and j. In other words I'd like to do something like: i = A j = B legend(1, 0.5, expression(sigma[i], sigma[j])) and have A and B as the actual subscripts. I can substitute the variable in the expression e.g.: legend(1, 0.5, substitute(sigma[i], list(i='A', j='B'))) legend(1, 0.5, bquote(sigma[.(i)])) however, this gives me just one of the two entries in the legend. I cannot figure out how to include both sigmas in the legend. What would be the best way to do something like this? Thank you for your ideas or suggestions. Aleksey -- Aleksey Naumov Department of Geography SUNY-Buffalo __ 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] Legend in xyplot two columns
Dear R-Help I have some trouble to set the legend in a xyplot into two rows. The code below gives me the legend in the layout I am looking for, I just rather have it in two rows. library(lattice) schluessel - list( points=list( col=red, pch=19, cex=0.5 ), text=list(lab=John), lines=list(col=blue), text=list(lab=Paul), lines=list(col=green), text=list(lab=George), lines=list(col=orange), text=list(lab=Ringo), rectangles = list(col= #CC, border=FALSE), text=list(lab=The Beatles), ) xyplot(1~1, key=schluessel) The next code gives me two rows, but repeates all the points,lines, and rectangles. schluessel2 - list( points=list( col=red, pch=19, cex=0.5 ), lines=list(col=c(blue, green, orange)), rectangles = list(col= #CC, border=FALSE), text=list(lab=c(John,Paul,George,Ringo, The Beatles)), columns=3, ) xyplot(1~1, key=schluessel2) So I think each list has to have 6 items, but some with no content. How do I do this? Thank you very much! Markus LNSCNTMCS01*** The information in this E-Mail and in any attachments is CON...{{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
Re: [R] Legend in xyplot two columns
On Thursday 14 April 2005 05:30, Gesmann, Markus wrote: Dear R-Help I have some trouble to set the legend in a xyplot into two rows. The code below gives me the legend in the layout I am looking for, I just rather have it in two rows. library(lattice) schluessel - list( points=list( col=red, pch=19, cex=0.5 ), text=list(lab=John), lines=list(col=blue), text=list(lab=Paul), lines=list(col=green), text=list(lab=George), lines=list(col=orange), text=list(lab=Ringo), rectangles = list(col= #CC, border=FALSE), text=list(lab=The Beatles), ) xyplot(1~1, key=schluessel) The next code gives me two rows, but repeates all the points,lines, and rectangles. schluessel2 - list( points=list( col=red, pch=19, cex=0.5 ), lines=list(col=c(blue, green, orange)), rectangles = list(col= #CC, border=FALSE), text=list(lab=c(John,Paul,George,Ringo, The Beatles)), columns=3, ) xyplot(1~1, key=schluessel2) So I think each list has to have 6 items, but some with no content. How do I do this? You could try using col=transparent to suppress things, but that's not a very satisfactory solution. The function to create the key is simply not designed to create unstructured legends like this. However, you can create an use an arbitrary ``grob'' (grid graphics object) for a legend, e.g.: ##- library(grid) library(lattice) fl - grid.layout(nrow = 2, ncol = 6, heights = unit(rep(1, 2), lines), widths = unit(c(2, 1, 2, 1, 2, 1), c(cm, strwidth, cm, strwidth, cm, strwidth), data = list(NULL, John, NULL, George, NULL, The Beatles))) foo - frameGrob(layout = fl) foo - placeGrob(foo, pointsGrob(.5, .5, pch=19, gp = gpar(col=red, cex=0.5)), row = 1, col = 1) foo - placeGrob(foo, linesGrob(c(0.2, 0.8), c(.5, .5), gp = gpar(col=blue)), row = 2, col = 1) foo - placeGrob(foo, linesGrob(c(0.2, 0.8), c(.5, .5), gp = gpar(col=green)), row = 1, col = 3) foo - placeGrob(foo, linesGrob(c(0.2, 0.8), c(.5, .5), gp = gpar(col=orange)), row = 2, col = 3) foo - placeGrob(foo, rectGrob(width = 0.6, gp = gpar(col=#CC, fill = #CC)), row = 1, col = 5) foo - placeGrob(foo, textGrob(lab = John), row = 1, col = 2) foo - placeGrob(foo, textGrob(lab = Paul), row = 2, col = 2) foo - placeGrob(foo, textGrob(lab = George), row = 1, col = 4) foo - placeGrob(foo, textGrob(lab = Ringo), row = 2, col = 4) foo - placeGrob(foo, textGrob(lab = The Beatles), row = 1, col = 6) xyplot(1 ~ 1, legend = list(top = list(fun = foo))) ##- HTH, Deepayan __ 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] Legend in xyplot two columns
Thanks Deepayan! Your solution does excatly what I want. Further experiments and thoughts on my side brought me also to a solution. If I use the option rep=FALSE, and plot the bullit with lines and split the lines argument into two groups it gives me the same result, as every item in the key list starts a new column. library(lattice) key - list( rep=FALSE, lines=list(col=c(red, blue), type=c(p,l), pch=19), text=list(lab=c(John,Paul)), lines=list(col=c(green, red), type=c(l, l)), text=list(lab=c(George,Ringo)), rectangles = list(col= #CC, border=FALSE), text=list(lab=The Beatles), ) xyplot(1~1, key=key) But your solution is much more felxible! Kind Regards Markus -Original Message- LNSCNTMCS01*** The information in this E-Mail and in any attachments is CONFIDENTIAL and may be privileged. If you are NOT the intended recipient, please destroy this message and notify the sender immediately. You should NOT retain, copy or use this E-mail for any purpose, nor disclose all or any part of its contents to any other person or persons. Any views expressed in this message are those of the individual sender, EXCEPT where the sender specifically states them to be the views of Lloyd's. Lloyd's may monitor the content of E-mails sent and received via its network for viruses or unauthorised use and for other lawful business purposes. Lloyd's is authorised under the Financial Services and Markets Act 2000 From: Deepayan Sarkar [mailto:[EMAIL PROTECTED] Sent: 14 April 2005 16:01 To: r-help@stat.math.ethz.ch Cc: Gesmann, Markus Subject: Re: [R] Legend in xyplot two columns On Thursday 14 April 2005 05:30, Gesmann, Markus wrote: Dear R-Help I have some trouble to set the legend in a xyplot into two rows. The code below gives me the legend in the layout I am looking for, I just rather have it in two rows. library(lattice) schluessel - list( points=list( col=red, pch=19, cex=0.5 ), text=list(lab=John), lines=list(col=blue), text=list(lab=Paul), lines=list(col=green), text=list(lab=George), lines=list(col=orange), text=list(lab=Ringo), rectangles = list(col= #CC, border=FALSE), text=list(lab=The Beatles), ) xyplot(1~1, key=schluessel) The next code gives me two rows, but repeates all the points,lines, and rectangles. schluessel2 - list( points=list( col=red, pch=19, cex=0.5 ), lines=list(col=c(blue, green, orange)), rectangles = list(col= #CC, border=FALSE), text=list(lab=c(John,Paul,George,Ringo, The Beatles)), columns=3, ) xyplot(1~1, key=schluessel2) So I think each list has to have 6 items, but some with no content. How do I do this? You could try using col=transparent to suppress things, but that's not a very satisfactory solution. The function to create the key is simply not designed to create unstructured legends like this. However, you can create an use an arbitrary ``grob'' (grid graphics object) for a legend, e.g.: ##- library(grid) library(lattice) fl - grid.layout(nrow = 2, ncol = 6, heights = unit(rep(1, 2), lines), widths = unit(c(2, 1, 2, 1, 2, 1), c(cm, strwidth, cm, strwidth, cm, strwidth), data = list(NULL, John, NULL, George, NULL, The Beatles))) foo - frameGrob(layout = fl) foo - placeGrob(foo, pointsGrob(.5, .5, pch=19, gp = gpar(col=red, cex=0.5)), row = 1, col = 1) foo - placeGrob(foo, linesGrob(c(0.2, 0.8), c(.5, .5), gp = gpar(col=blue)), row = 2, col = 1) foo - placeGrob(foo, linesGrob(c(0.2, 0.8), c(.5, .5), gp = gpar(col=green)), row = 1, col = 3) foo - placeGrob(foo, linesGrob(c(0.2, 0.8), c(.5, .5), gp = gpar(col=orange)), row = 2, col = 3) foo - placeGrob(foo, rectGrob(width = 0.6, gp = gpar(col=#CC, fill = #CC)), row = 1, col = 5) foo - placeGrob(foo, textGrob(lab = John), row = 1, col = 2) foo - placeGrob(foo, textGrob(lab = Paul), row = 2, col = 2) foo - placeGrob(foo, textGrob(lab = George), row = 1, col = 4) foo - placeGrob(foo
Re: [R] Legend in xyplot two columns
On Thursday 14 April 2005 10:29, Gesmann, Markus wrote: Thanks Deepayan! Your solution does excatly what I want. Further experiments and thoughts on my side brought me also to a solution. If I use the option rep=FALSE, and plot the bullit with lines and split the lines argument into two groups it gives me the same result, as every item in the key list starts a new column. Of course. I'd forgotten that 'lines' can also be points. Deepayan __ 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