Adding ridgeline plot from ggridges. [WIP]#258
Adding ridgeline plot from ggridges. [WIP]#258jenzopr wants to merge 2 commits intoggobi:masterfrom jenzopr:master
Conversation
Codecov Report
@@ Coverage Diff @@
## master #258 +/- ##
=========================================
- Coverage 97.78% 97.6% -0.19%
=========================================
Files 25 25
Lines 4246 4254 +8
=========================================
Hits 4152 4152
- Misses 94 102 +8
Continue to review full report at Codecov.
|
|
Hi Jens, I like the idea, but I'm cautious about the movement of label position. Because of this I don't know if I can include it. I'd like to be a stickler to that rule. However, I would like to make it easier to extend the functionality, so ggpairs(iris, 3:5, lower = list(combo = "density_ridges"))Needed fixes:
I'd also like to include a "Known Extensions" or something somewhere on GitHub. Idk how it'd work as a pkg vignette, as I don't want to make circular dependancies. Even a list that points to GitHub/cran docs would be a great start. Thoughts?
Works with user session, but not with reprex::reprex (which is 'cleaner'). Need to not look in just GGally package, but just for 'ggally_*'. library(GGally)
ggally_density_ridges <- function(data, mapping, ...) {
require(ggridges)
horizontal <- GGally:::is_horizontal(data, mapping)
if (!horizontal) {
mapping <- GGally:::mapping_swap_x_y(mapping)
}
mapping <- GGally:::mapping_color_to_fill(mapping)
ggplot2::ggplot(data) + ggridges::geom_density_ridges2(mapping, ...)
}
## really neat! Each label is at the correct position, but overlap is
## achieved
ggpairs(iris, 3:5, lower = list(combo = "density_ridges"))
#> Error in value[[3L]](cond): The following ggpairs plot functions are readily available:
#> continuous: c('points', 'smooth', 'smooth_loess', 'density', 'cor', 'blank')
#> combo: c('box', 'box_no_facet', 'dot', 'dot_no_facet', 'facethist', 'facetdensity', 'denstrip', 'blank')
#> discrete: c('ratio', 'facetbar', 'blank')
#> na: c('na', 'blank')
#>
#> diag continuous: c('densityDiag', 'barDiag', 'blankDiag')
#> diag discrete: c('barDiag', 'blankDiag')
#> diag na: c('naDiag', 'blankDiag')
#>
#> You may also provide your own function that follows the api of function(data, mapping, ...){ . . . }
#> and returns a ggplot2 plot object
#> Ex:
#> my_fn <- function(data, mapping, ...){
#> p <- ggplot(data = data, mapping = mapping) +
#> geom_point(...)
#> p
#> }
#> ggpairs(data, lower = list(continuous = my_fn))
#>
#> Function provided: density_ridges
ir <- iris
ir$Species <- factor(as.character(iris$Species), levels = c("versicolor", "virginica",
"setosa"))
## labels on the left side are squished, as 'setosa' requires more space.
ggpairs(ir, 3:5, lower = list(combo = "density_ridges"))
#> Error in value[[3L]](cond): The following ggpairs plot functions are readily available:
#> continuous: c('points', 'smooth', 'smooth_loess', 'density', 'cor', 'blank')
#> combo: c('box', 'box_no_facet', 'dot', 'dot_no_facet', 'facethist', 'facetdensity', 'denstrip', 'blank')
#> discrete: c('ratio', 'facetbar', 'blank')
#> na: c('na', 'blank')
#>
#> diag continuous: c('densityDiag', 'barDiag', 'blankDiag')
#> diag discrete: c('barDiag', 'blankDiag')
#> diag na: c('naDiag', 'blankDiag')
#>
#> You may also provide your own function that follows the api of function(data, mapping, ...){ . . . }
#> and returns a ggplot2 plot object
#> Ex:
#> my_fn <- function(data, mapping, ...){
#> p <- ggplot(data = data, mapping = mapping) +
#> geom_point(...)
#> p
#> }
#> ggpairs(data, lower = list(continuous = my_fn))
#>
#> Function provided: density_ridges |
|
Hi Barret, nice feature, I didn't know that it would look in the global env for a function prefixed by Best, |
|
Closing in favor of #309 |

Hi Barret,
I recently started to include ridgeline plots in my ggpairs figures that I create for some projects. I thought it would be a nice idea to make those plots available for all GGally users.
This PR adds a wrapper for
ggridges::geom_density_ridgesasggally_density_ridges.It does not yet do much, except making sure the plot is horizontal and the
colormapping is mapped tofillinstead.Since there might be some pitfalls when including into
GGally, I would like to hear your comments and later extend this PR.Looking forward to your reply.
Best,
Jens