jespermaag / gganatogram

Create anatograms using ggplot2
379 stars 52 forks source link

trying to allow ggplotly to work on this #14

Closed muschellij2 closed 5 years ago

muschellij2 commented 5 years ago

So geom_GeomPolyPath doesn't translate in plotly::ggplotly. plotly::ggplotly allows you to make interactive graphics - without extra code! So if you use ggplot2_only, then the figure itself doesn't look correct (see below). This is likely differences from geom_polygon and geom_poly compared to geom_polypath. But when you use ggplotly on the output - this seems to work well and agrees with the original output. I think you may need to regroup some of the nerve data (may be others as well) if you want "accurate" polygons from ggplot2.

TL; DR - use ggplot2_only when using plotly::ggplotly and you can get interactivity!

library(ggplot2)
library(plotly)
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(gganatogram)
#> Loading required package: ggpolypath
organPlot <- data.frame(organ = c("heart", "leukocyte", "nerve", "brain",
                                  "liver", "stomach", "colon"),
                        type = c("circulation", "circulation",
                                 "nervous system", "nervous system", "digestion", "digestion",
                                 "digestion"),
                        colour = c("red", "red", "purple", "purple", "orange",
                                   "orange", "orange"),
                        value = c(10, 5, 1, 8, 2, 5, 5),
                        stringsAsFactors=FALSE)

g = gganatogram(data = organPlot, ggplot2_only = FALSE)
g

ggplotly(g)
#> Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues

#> Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[2L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[3L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[4L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[5L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[6L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues
#> Warning in geom2trace.default(dots[[1L]][[7L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomPolypath() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues


g4 = gganatogram(data = organPlot, fill = "value",
                 show_legend = FALSE)
#> Warning: Ignoring unknown aesthetics: text
g4


g2 = gganatogram(data = organPlot, ggplot2_only = TRUE)
g2

ggplotly(g2)


g3 = gganatogram(data = organPlot, fill = "value", ggplot2_only = TRUE)
#> Warning: Ignoring unknown aesthetics: text
g3

ggplotly(g3, tooltip = c("value", "organ"))

Created on 2018-09-19 by the reprex package (v0.2.0).

jespermaag commented 5 years ago

What do you think of integrating ggplotly into another function called gganatogram_plotly or gganatogram_interactive instead of the main function. This way we would avoid the weird static plot behaviour.

muschellij2 commented 5 years ago

I think that's fine, but then you need to duplicate all the code unless you reimplement the plot in plotly itself and not ggplot.

John

On Thu, Sep 20, 2018 at 8:38 AM Jesper Maag notifications@github.com wrote:

What do you think of integrating ggplotly into another function called gganatogram_plotly or gganatogram_interactive instead of the main function. This way we would avoid the weird static plot behaviour.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jespermaag/gganatogram/pull/14#issuecomment-423167379, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBnrr6BAuhiQAoa84D97DxwTBxEpXeIks5uc4xRgaJpZM4WxGCj .

jespermaag commented 5 years ago

You're right John, it's not a good option. I'll think about what's best