[R] ggplot questions

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Jun 6 10:02:19 CEST 2008


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

------------------------------------------------------------------------
----
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
Thierry.Onkelinx op inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Thompson, David (MNR)
Verzonden: donderdag 5 juni 2008 21:38
Aan: hadley wickham
CC: r-help op r-project.org
Onderwerp: Re: [R] ggplot questions

Thanx Hadley, 

More questions inline.

>-----Original Message-----
>From: hadley wickham [mailto:h.wickham op gmail.com] 
>Sent: June 5, 2008 01:09 PM
>To: Thompson, David (MNR)
>Cc: r-help op r-project.org
>Subject: Re: [R] ggplot questions
>
>On Wed, Jun 4, 2008 at 2:03 PM, Thompson, David (MNR)
><David.John.Thompson op ontario.ca> 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.6        colorspace_0.95    RColorBrewer_1.0-2
MASS_7.2-42        proto_0.3-8        reshape_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
david.john.thompson op ontario.ca
http://ontario.ca/ofri

______________________________________________
R-help op 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.



More information about the R-help mailing list