[R] ggplot2, geom_hline and facet_grid
Hadley Wickham
hadley at rice.edu
Wed Jan 19 16:11:43 CET 2011
Hi Sandy,
It's difficult to know what's going wrong without a small reproducible
example (https://github.com/hadley/devtools/wiki/Reproducibility) -
could you please provide one? You might also have better luck with an
email directly to the ggplot2 mailing list.
Hadley
On Wed, Jan 19, 2011 at 2:57 AM, Sandy Small <sandy.small at nhs.net> wrote:
> Having upgraded to R version 2.12.1 I still have the same problem:
>
> The combination of facet_grid and geom_hline produce (for me) 4 panels
> of which two are empty of any data or lines (labelled "1" and "2").
> Removing either the facet_grid or the geom_hline gives me the result I
> would then expect.
>
> I have tried forcing the rhythm to be a factor
> Anyone have any ideas?
>
> Sandy
>
> Dennis Murphy wrote:
>
> Hi:
>
> The attached plot comes from the following code:
>
> g <- ggplot(data =f, aes(x = (variable_time + fixed_time)/2, y
> variable_time - fixed_time))
> g + geom_point() + geom_hline(yintercept =) + facet_grid(ecd_rhythm ~ .)
>
> Is this what you were expecting?
>
> > sessionInfo()
> R version 2.12.1 Patched (2010-12-18 r53869)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=glish_United States.1252
> [2] LC_CTYPE=glish_United States.1252
> [3] LC_MONETARY=glish_United States.1252
> [4] LC_NUMERIC=nbsp;
> [5] LC_TIME=glish_United States.1252
>
> attached base packages:
> [1] splines stats graphics grDevices utils datasets
> grid
> [8] methods base
>
> other attached packages:
> [1] data.table_1.5.1 doBy_4.2.2 R2HTML_2.2 contrast_0.13
> [5] Design_2.3-0 Hmisc_3.8-3 survival_2.36-2 sos_1.3-0
> [9] brew_1.0-4 lattice_0.19-17 ggplot2_0.8.9 proto_0.3-8
> [13] reshape_0.8.3 plyr_1.4
>
> loaded via a namespace (and not attached):
> [1] cluster_1.13.2 digest_0.4.2 Matrix_0.999375-46
> reshape2_1.1
> [5] stringr_0.4 tools_2.12.1
>
> HTH,
> Dennis
>
> On Tue, Jan 18, 2011 at 1:46 AM, Small Sandy (NHS Greater Glasgow &
> Clyde) <sandy.small at nhs.net <ailto:sandy.small at nhs.net%22>> wrote:
>
> Hi
>
> I have a long data set on which I want to do Bland-Altman style
> plots for each rhythm type
> Using ggplot2, when I use geom_hline with facet_grid I get an
> extra set of empty panels.
> I can't get it to do it with the "Diamonds" data supplied with
> the package so here is a (much abbreviated) example:
>
> > lvexs
> cvd_basestudy ecd_rhythm fixed_time variable_time
> 1 CBP05J02 AF 30.9000 29.4225
> 2 CBP05J02 AF 33.1700 32.0350
> 3 CBP05J02 AF 32.5700 30.2775
> 4 CBP05J02 AF 32.0550 33.7275
> 5 CBP05J02 SINUS 30.9175 28.3475
> 6 CBP05J02 SINUS 30.5725 29.7450
> 7 CBP05J02 SINUS 33.0000 31.1550
> 9 CBP05J02 SINUS 31.8350 30.7000
> 10 CBP05J02 SINUS 34.0450 33.4800
> 11 CBP05J02 SINUS 31.3975 29.8150
> > qplot((variable_time + fixed_time)/2, variable_time -
> fixed_time, data=exs) + facet_grid(ecd_rhythm ~ .) +
> geom_hline(yintercept=0)
>
> If I take out the geom_hline I get the plots I would expect.
>
> It doesn't seem to make any difference if I get the mean and
> difference separately.
>
> Can anyone explain this and tell me how to avoid it (and why
> does it work with the Diamonds data set?
>
> Any help much appreciated - thanks.
>
> Sandy
>
> Sandy Small
> Clinical Physicist
> NHS Forth Valley
> and
> NHS Greater Glasgow and Clyde
>
>
>
> ********************************************************************************************************************
>
> This message may contain confidential information. If yo...{{dropped:21}}
>
> ______________________________________________
> R-help at 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.
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-help
mailing list