Created
January 19, 2011 21:24
-
-
Save SandySmall/786894 to your computer and use it in GitHub Desktop.
Using facet_grid and geom_hline together produces 2 empty extra panels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Packages | |
# | |
library(ggplot2) | |
# | |
# Data: 4 column dataframe. | |
# This is the first 10 rows of the dataframe but it makes the point | |
# | |
lvefeg <- structure(list(cvd_basestudy = c("CBP05J02", "CBP05J02", "CBP05J02", | |
"CBP05J02", "CBP05J02", "CBP05J02", "CBP05J02", "CBP05J02", "CBP05J02", | |
"CBP05J02"), ecd_rhythm = c("AF", "AF", "AF", "AF", "AF", "SINUS", | |
"SINUS", "SINUS", "SINUS", "SINUS"), fixed_time = c(30.9, 33.17, | |
32.57, 32.055, 30.9175, 30.5725, 33, 31.835, 34.045, 31.3975), | |
variable_time = c(29.4225, 32.035, 30.2775, 33.7275, 28.3475, | |
29.745, 31.155, 30.7, 33.48, 29.815)), .Names = c("cvd_basestudy", | |
"ecd_rhythm", "fixed_time", "variable_time"), class = c("cast_df", | |
"data.frame"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 9L, | |
10L, 11L)) | |
# | |
# Plot it: | |
# Looking to plot 2 panels showing the difference between variable | |
# and fixed time measures against the mean of the measures. The panels are | |
# separated by the ecg_rhythm | |
# | |
# THE PROBLEM is that it produces 4 panels the top two are empty | |
# the bottom two are as expected | |
p <- qplot((variable_time + fixed_time) /2 , variable_time - fixed_time, data = lvefeg, geom='point') | |
p + facet_grid(ecd_rhythm ~ .) + geom_hline(yintercept=0) | |
# | |
# The same result is obtained with: | |
# (Commented out here) | |
# | |
#g <- ggplot(lvefeg, aes(x=(variable_time + fixed_time)/2, y = variable_time - fixed_#time)) | |
#g + geom_point() + facet_grid(ecd_rhythm ~ .) + geom_hline(yintercept=0) | |
# | |
# sessionInfo() output | |
# | |
#> sessionInfo() | |
#R version 2.12.1 (2010-12-16) | |
#Platform: i386-redhat-linux-gnu (32-bit) | |
# | |
#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] grid stats graphics grDevices utils datasets methods | |
#[8] base | |
# | |
#other attached packages: | |
#[1] ggplot2_0.8.9 proto_0.3-8 reshape_0.8.3 plyr_1.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment