Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use aes() and pass (or wrap) custom functions #90

Merged
merged 44 commits into from
Oct 25, 2015
Merged

use aes() and pass (or wrap) custom functions #90

merged 44 commits into from
Oct 25, 2015

Conversation

schloerke
Copy link
Member

be able to pass functions directly to ggpairs

Ex:

data("tips", package = "reshape")
pm <- ggpairs(
  tips, 
  columns = 1:3, 
  mapping = ggplot2::aes(color = sex), 
  lower = list(
    combo = wrap("facethist", binwidth = 1),
    continuous = wrap(ggally_points, size = 5)
  )
)
pm

screenshot 2015-09-08 23 47 48

> str(pm)

Custom str.ggmatrix output: 
To view original object use 'str(pm, raw = TRUE)'

List of 13
 $ data       :'data.frame':    244 obs. of  7 variables:
  ..$ total_bill: num [1:244] 17 10.3 21 23.7 24.6 ...
  ..$ tip       : num [1:244] 1.01 1.66 3.5 3.31 3.61 4.71 2 3.12 1.96 3.23 ...
  ..$ sex       : Factor w/ 2 levels "Female","Male": 1 2 2 2 1 2 2 2 2 2 ...
  ..$ smoker    : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
  ..$ day       : Factor w/ 4 levels "Fri","Sat","Sun",..: 3 3 3 3 3 3 3 3 3 3 ...
  ..$ time      : Factor w/ 2 levels "Dinner","Lunch": 1 1 1 1 1 1 1 1 1 1 ...
  ..$ size      : int [1:244] 2 3 3 2 4 4 2 4 2 2 ...
 $ plots      :List of 9
  ..$ : chr "PM; aes: c(x = total_bill, colour = sex); fn: {wrap; fn: 'ggally_densityDiag'; with params: c()}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = tip, y = total_bill, colour = sex); fn: {wrap; fn: 'ggally_cor'; with params: c()}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = sex, y = total_bill, fill = sex); fn: {wrap; fn: 'ggally_box'; with params: c()}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = total_bill, y = tip, colour = sex); fn: {wrap; fn: 'funcVal'; with params: c(size = 5)}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = tip, colour = sex); fn: {wrap; fn: 'ggally_densityDiag'; with params: c()}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = sex, y = tip, fill = sex); fn: {wrap; fn: 'ggally_box'; with params: c()}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = total_bill, y = sex, fill = sex); fn: {wrap; fn: 'ggally_facethist'; with params: c(binwidth = 1)}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = tip, y = sex, fill = sex); fn: {wrap; fn: 'ggally_facethist'; with params: c(binwidth = 1)}; gg: FALSE"
  ..$ : chr "PM; aes: c(x = sex, fill = sex); fn: {wrap; fn: 'ggally_barDiag'; with params: c()}; gg: FALSE"
 $ title      : chr ""
 $ verbose    : logi FALSE
 $ printInfo  : logi FALSE
 $ axisLabels : chr "show"
 $ xAxisLabels: chr [1:3] "total_bill" "tip" "sex"
 $ yAxisLabels: chr [1:3] "total_bill" "tip" "sex"
 $ legends    : logi FALSE
 $ gg         : NULL
 $ nrow       : int 3
 $ ncol       : int 3
 $ byrow      : logi TRUE
 - attr(*, "_class")= chr [1:2] "gg" "ggmatrix"```

@schloerke
Copy link
Member Author

@briatte, can you take a look at this branch and mess around with ggpairs? I'd like to see if it's more fluid / non confusing.

I still have to reduce the parameters in the main ggally_(plot)s, but I'll do that tomorrow. corUse -> use

@briatte
Copy link
Contributor

briatte commented Sep 9, 2015

@schloerke I'm looking at the function's examples right now, after adapting them to a different dataset (the hdv2003 dataset in package questionr, which is a social survey with mostly ordinal/factor variables).

Here are two first impressions:

  • you need a vignette

I believe that you really need a vignette for ggpairs – there's tons of great options, but few ways to discover them from the package.

In fact, as far as I understand, pretty much every major function of GGally requires a vignette. Perhaps this could be made a requirement for a function to be included in the package. Since graphics-based vignettes are heavy in size, I would recommend keeping them out of the package itself, and host them on GitHub instead.

  • you need a "blank" default theme, and/or a theme argument

ggpairs uses theme_grey by default, but if you are emulating the pairs function, I believe it would make great sense to use theme_bw or something like that instead. In most of the examples that I ran, I found myself wanting the grey background (and panel grid) out, and axis labels to be more readable (i.e. printed in black instead of grey).

Adding a theme to ggpairs object does not propagate the theme to its components:

library(questionr)
data(hdv2003)
p = ggpairs(
  hdv2003[, 2:4 ],
  upper = list(continuous = "density", combo = "box"),
  lower = list(continuous = "points", combo = "dot")
)
p + theme_bw()

How about allowing this:

ggpairs(
  hdv2003[, 2:4 ],
  upper = list(continuous = "density", combo = "box"),
  lower = list(continuous = "points", combo = "dot"),
  theme = theme_bw()
)

What do you think?

* params: (46 commits)
  typo
  fixed stringr imports issue
  fixed tests for ggpairs
  add 'Diag' to all diagonal plot fns.  must require Diag for diagonal plots
  documented
  added rescale arg to barDiag and densityDiag
  fixed typo
  document
  better name recognition for functions supplied within ggpairs
  fix examples in ggpairs
  document mapping in ggpairs
  clearer error message when supplying a nonexistent function
  updated ggally_cor to use non-ugly args
  better naming for wraps
  remove params args in tests of ggpairs
  fix tests to use updated mapping arg and wrap all binwidth fns
  make whole error output into one output
  if a wrapped function is wrapped again, reduce to one wrap
  more ways to check if a plot is blank
  documented
  ...
* params:
  documented
  documented
  updated Roxygen version to 4.1.1
@schloerke schloerke merged commit 01542ab into dev Oct 25, 2015
@schloerke schloerke deleted the params branch October 26, 2015 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants