Re: [R] ggplot questions
Thanx Thierry, Suggestion #1 had no effect. I have been playing with variants on #2 along the way. DaveT. -Original Message- From: ONKELINX, Thierry [mailto:[EMAIL PROTECTED] Sent: June 6, 2008 04:02 AM To: Thompson, David (MNR); hadley wickham Cc: r-help@r-project.org Subject: RE: [R] ggplot questions David, 1. Try scale_x_continuous(lim = c(0, 360)) + scale_y_continuous(lim = c(0, 16)) 2. You could set the colour of the gridlines equal to the backgroup colour with ggopt HTH, Thierry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot questions
Does the difference have something to do with ggplot() using ranges derived from the data? When I modify my original 'test' dataframe with two extra rows as defined below, I get expected results in both versions. Order shouldn't matter - and if it's making a difference, that's a bug. But I'm still not completely sure what you're expecting. This highlights my next question (warned you ;-) ), I have been unsuccessful in trying to define fixed plotting ranges to generate a 'template' graphic that I may reuse with successive 'overstory plot' data sets. I have used '+ xlim(0, 360) + ylim(0, 16)' but, this seems to not have any effect on the final plot layout. Could you please produce a small reproducible example that demonstrates this? It may well be a bug. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot questions
OK, The original ggplot() construct (below) on the following two dataframes (test1, test2) generate different outputs, which I have attached. The output that I expect is that shown in test2.png. My expectations are that I have set the plotting limits with 'scale_x_continuous(lim = c(0, 360)) + scale_y_continuous(lim = c(0, 16))' so, both data sets should produce the same output except for the 'o' at plot center and the 'N' at the top. The only difference in the two dataframes are inclusion of first two rows in test2 with rplt column changed to character: test2[1:2,] oplt rplt az dist 10o 00 20N 360 16 Ahhh, wait a second! In composing this message I may have found the problem. It appears that including the 'scale_x_continuous()' component twice in my original version was causing (?) the erratic behaviour. And I have confirmed that the ordering of the layer, scale* and coord* components does not affect the output. However, I'm still getting more x-breaks than requested with radial lines corresponding to 45, 135, 225, 315 degrees (NE, SE, SW, NW). Still open to suggestions on that. # new version working with both dataframes ggplot() + coord_polar() + layer( data = test1, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(lim = c(0, 360), breaks=c(90, 180, 270, 360), labels=c('E', 'S', 'W', 'N')) + scale_y_continuous(lim = c(0, 16), breaks=c(0, 4, 8, 12, 16), labels=c('centre', '4m', '8m', '12m', '16m')) ## ## ## # original version NOT WORKING with test1 ggplot() + coord_polar() + scale_x_continuous(lim = c(0, 360)) + scale_y_continuous(lim = c(0, 16)) + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360), labels=c('90', '180', '270', '360')) # data generating test1.png test1 -structure(list(oplt = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), rplt = 1:10, az = c(57L, 94L, 96L, 152L, 182L, 185L, 227L, 264L, 332L, 354L), dist = c(4.09, 2.8, 7.08, 7.09, 3.28, 7.85, 6.12, 1.97, 7.68, 7.9)), .Names = c(oplt, rplt, az, dist ), row.names = c(NA, 10L), class = data.frame) # data generating test2.png test2 - structure(list(oplt = c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), rplt = c(o, N, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), az = c(0, 360, 57, 94, 96, 152, 182, 185, 227, 264, 332, 354), dist = c(0, 16, 4.09, 2.8, 7.08, 7.09, 3.28, 7.85, 6.12, 1.97, 7.68, 7.9)), .Names = c(oplt, rplt, az, dist), row.names = c(NA, 12L), class = data.frame) Many, many thanks for your patience and perseverance on this one Hadley, DaveT. -Original Message- From: hadley wickham [mailto:[EMAIL PROTECTED] Sent: June 6, 2008 02:06 PM To: Thompson, David (MNR) Cc: r-help@r-project.org Subject: Re: [R] ggplot questions Does the difference have something to do with ggplot() using ranges derived from the data? When I modify my original 'test' dataframe with two extra rows as defined below, I get expected results in both versions. Order shouldn't matter - and if it's making a difference, that's a bug. But I'm still not completely sure what you're expecting. This highlights my next question (warned you ;-) ), I have been unsuccessful in trying to define fixed plotting ranges to generate a 'template' graphic that I may reuse with successive 'overstory plot' data sets. I have used '+ xlim(0, 360) + ylim(0, 16)' but, this seems to not have any effect on the final plot layout. Could you please produce a small reproducible example that demonstrates this? It may well be a bug. Hadley -- http://had.co.nz/ attachment: test1.pngattachment: test2.png__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot questions
On Wed, Jun 4, 2008 at 2:03 PM, Thompson, David (MNR) [EMAIL PROTECTED] wrote: Hello, A few questions about the following examples: 1. Why do the two plotting versions not produce the same result? Because version one has two layers, and version two has one? 2. Is the 'scale_x_continuous' (or *_y_* or *_*_discrete) geom the best way to setup grids (as in visual guide-lines) in polar (or for that matter, any) coordinate system? It's one way. Another way is to use geom_hline and geom_vline. (Also note that scale_x_continuous is a _scale_ not a geom) 3. Why do these commands appear to generate 3 plot pages each? Could you provide a bit more detail here please? Thanks, Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot questions
Thanx Hadley, More questions inline. -Original Message- From: hadley wickham [mailto:[EMAIL PROTECTED] Sent: June 5, 2008 01:09 PM To: Thompson, David (MNR) Cc: r-help@r-project.org Subject: Re: [R] ggplot questions On Wed, Jun 4, 2008 at 2:03 PM, Thompson, David (MNR) [EMAIL PROTECTED] wrote: Hello, A few questions about the following examples: 1. Why do the two plotting versions not produce the same result? Because version one has two layers, and version two has one? Does the difference have something to do with ggplot() using ranges derived from the data? When I modify my original 'test' dataframe with two extra rows as defined below, I get expected results in both versions. This highlights my next question (warned you ;-) ), I have been unsuccessful in trying to define fixed plotting ranges to generate a 'template' graphic that I may reuse with successive 'overstory plot' data sets. I have used '+ xlim(0, 360) + ylim(0, 16)' but, this seems to not have any effect on the final plot layout. 2. Is the 'scale_x_continuous' (or *_y_* or *_*_discrete) geom the best way to setup grids (as in visual guide-lines) in polar (or for that matter, any) coordinate system? It's one way. Another way is to use geom_hline and geom_vline. (Also note that scale_x_continuous is a _scale_ not a geom) OK. So, how do I suppress automatic generation of plot grids so that I could define my own with geom_hline and geom_vline? 3. Why do these commands appear to generate 3 plot pages each? Could you provide a bit more detail here please? Sorry Hadley, I could not reproduce the same behaviour. I had restarted my computer since then so, maybe, I was just suffering from the usual leaky-resources-M$-syndrome. Thanks, Hadley -- http://had.co.nz/ # for ease of reference: # the two original dataframes test - structure(list(oplt = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), rplt = 1:10, az = c(57L, 94L, 96L, 152L, 182L, 185L, 227L, 264L, 332L, 354L), dist = c(4.09, 2.8, 7.08, 7.09, 3.28, 7.85, 6.12, 1.97, 7.68, 7.9)), .Names = c(oplt, rplt, az, dist ), row.names = c(NA, 10L), class = data.frame) labs - structure(list(oplt = c(0, 0, 0, 0, 0), rplt = structure(c(3L, 1L, 4L, 5L, 2L), .Label = c(E, N, o, S, W), class = factor), az = c(0, 90, 180, 270, 360), dist = c(0, 16, 16, 16, 16)), .Names = c(oplt, rplt, az, dist), row.names = c(NA, -5L), class = data.frame) # the new dataframe test2 - structure(list(oplt = c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), rplt = c(o, N, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), az = c(0, 360, 57, 94, 96, 152, 182, 185, 227, 264, 332, 354), dist = c(0, 16, 4.09, 2.8, 7.08, 7.09, 3.28, 7.85, 6.12, 1.97, 7.68, 7.9)), .Names = c(oplt, rplt, az, dist), row.names = c(NA, 12L), class = data.frame) ### plot version 1, setup plot structure first, add 'data' points later ggplot() + coord_polar() + layer( data = labs, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360)) + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) ### plot version 2, try the same all in one step ggplot() + coord_polar() + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360), labels=c('90', '180', '270', '360')) sessionInfo() R version 2.7.0 (2008-04-22) i386-pc-mingw32 locale: LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY= English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252 attached base packages: [1] datasets grDevices splines grid graphics stats tcltk utils methods base other attached packages: [1] ggplot2_0.6colorspace_0.95RColorBrewer_1.0-2 MASS_7.2-42proto_0.3-8reshape_0.8.0 car_1.2-8 [8] svSocket_0.9-5 svIO_0.9-5 R2HTML_1.59 svMisc_0.9-5 svIDE_0.9-5 Thanx again, DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ontario.ca/ofri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ggplot questions
Hello, A few questions about the following examples: 1. Why do the two plotting versions not produce the same result? 2. Is the 'scale_x_continuous' (or *_y_* or *_*_discrete) geom the best way to setup grids (as in visual guide-lines) in polar (or for that matter, any) coordinate system? 3. Why do these commands appear to generate 3 plot pages each? 4. Perhaps more questions to follow ;-) ### the data test - structure(list(oplt = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), rplt = 1:10, az = c(57L, 94L, 96L, 152L, 182L, 185L, 227L, 264L, 332L, 354L), dist = c(4.09, 2.8, 7.08, 7.09, 3.28, 7.85, 6.12, 1.97, 7.68, 7.9)), .Names = c(oplt, rplt, az, dist ), row.names = c(NA, 10L), class = data.frame) labs - structure(list(oplt = c(0, 0, 0, 0, 0), rplt = structure(c(3L, 1L, 4L, 5L, 2L), .Label = c(E, N, o, S, W), class = factor), az = c(0, 90, 180, 270, 360), dist = c(0, 16, 16, 16, 16)), .Names = c(oplt, rplt, az, dist), row.names = c(NA, -5L), class = data.frame) ### plot version 1, setup plot structure first, add 'data' points later ggplot() + coord_polar() + layer( data = labs, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360)) + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) ### plot version 2, try the same all in one step ggplot() + coord_polar() + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360), labels=c('90', '180', '270', '360')) ### the scenario I am generating graphics to show the physical layout of a forestry research experiment. There are 54 'cut blocks' (64x64m, 0.4ha) each containing 1 circular 'overstory plot' (16m radius, 0.08ha). Each 'overstory plot' (oplt) contains 10 circular 'regeneration plots' (rplt) (0.56m radius, 1m^2 or 1.13m radius, 4m^2), these are the label data points plotted below, later to have the 1m^2 or 4m^2 rplt outline added. Later, each individual tree will be plotted across each oplt in the views below and each rplt in expanded views. All locations (rplt centers, tree positions) are recorded as azimuth and distance from their respective plot centers, hence my inclination to use polar coordinates. Thanx, DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ontario.ca/ofri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.