I'm trying to graph data in facets, and that data has widely varying scales, seemingly calling for the use of "scales = 'free'". Here's a simple example.
Enter code here.library(ggplot2)
library(scales)
library(dplyr)
library(broom)
data(mtcars)
mtcars %>%
mutate(gpm = 1/mpg) %>%
ggplot(aes(x = wt, y = gpm)) +
geom_point() +
facet_grid(am ~ cyl, scales = 'free')
## > sessionInfo()
## R version 3.3.1 (2016-06-21)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
## 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] stats graphics grDevices utils datasets methods base
## other attached packages:
## [1] broom_0.4.1 dplyr_0.5.0 scales_0.4.0 ggplot2_2.1.0
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.7 magrittr_1.5 mnormt_1.5-4 munsell_0.4.3
## [5] colorspace_1.2-6 lattice_0.20-34 R6_2.1.3 stringr_1.1.0
## [9] plyr_1.8.4 tools_3.3.1 parallel_3.3.1 grid_3.3.1
## [13] gtable_0.2.0 nlme_3.1-128 psych_1.6.9 DBI_0.5-1
## [17] digest_0.6.10 lazyeval_0.2.0 assertthat_0.1 tibble_1.2
## [21] reshape2_1.4.1 tidyr_0.6.0 labeling_0.3 stringi_1.1.1
## [25] compiler_3.3.1 foreign_0.8-67
..
On my screen, I see 2 rows of 3 graphs each. The abscissas have different scales in each column, and the ordinates have different scales in each row. However, each of the graphs in the two rows would seem to warrant different scales on their ordinate, but they share the same one. Similarly, each of the graphs in the three columns would seem to warrant different scales on their abscissas, but they share a common one.
If I run this code, instead, I get the scaling I expect, but the facet headers are not as I want.
mtcars %>%
mutate(gpm = 1/mpg) %>%
ggplot(aes(x = wt, y = gpm)) +
geom_point() +
facet_wrap(am ~ cyl, scales = 'free')
Is it possible to do what I want? The documentation for the scales argument on the facet_grid and facet_wrap pages is not identical, and facet_grid may be not capable of doing what I want. Still, my real data produces one graph that goes from about 1 to 1,000 and another that goes from perhaps 20,000 to 60,000, and the corresponding facet_grid command above is unusable. Having a command that handled free scales as facet_wrap does and graph headers as facet_grid does would be really nice.
Thanks,
Bill