[R] ggplot2, geom_hline and facet_grid

Small Sandy (NHS Greater Glasgow & Clyde) sandy.small at nhs.net
Tue Jan 18 14:51:23 CET 2011


Thanks Dennis

Yes the plot you sent was what I was expecting. Unfortunately I do not get the same thing using the same commands whn I try it.
I notice that I am using a slightly earlier version of R than you. Given that it worked on the Diamonds data I doubt that this the problem but I will upgrade this evening and see if it makes any difference.

Here is my session info:

> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-redhat-linux-gnu

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
 [5] LC_MONETARY=C              LC_MESSAGES=en_GB.UTF-8
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  grid      methods
[8] base

other attached packages:
[1] ggplot2_0.8.9 reshape_0.8.3 plyr_1.4      proto_0.3-8

Sandy Small
Clinical Physicist
NHS Forth Valley
and
NHS Greater Glasgow and Clyde
________________________________________
From: Dennis Murphy [djmuser at gmail.com]
Sent: 18 January 2011 11:41
To: Small Sandy (NHS Greater Glasgow & Clyde)
Subject: Re: [R] ggplot2, geom_hline and facet_grid

Hi:

The attached plot comes from the following code:

g <- ggplot(data = df, aes(x = (variable_time + fixed_time)/2, y = variable_time - fixed_time))
g + geom_point() + geom_hline(yintercept = 0) + 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=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_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<mailto:sandy.small at nhs.net>> 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=lvexs) + 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<mailto: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.


********************************************************************************************************************

This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.

Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and GSi recipients
NHSmail provides an email address for your career in the NHS and can be accessed anywhere
For more information and to find out how you can switch, visit www.connectingforhealth.nhs.uk/nhsmail



More information about the R-help mailing list