plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

ggplot2 extension packages

Open cpsievert opened this issue 8 years ago • 21 comments

Extensions that we'd like ggplotly() to support

  • [ ] ggraph, ggforce https://github.com/plotly/plotly.R/pull/1326
  • [ ] forecast https://github.com/plotly/plotly.R/pull/2045
  • [ ] ggpubr::stat_compare_means() (and maybe others from https://github.com/kassambara/ggpubr?)
  • [ ] https://github.com/business-science/tidyquant
  • [ ] https://github.com/mjskay/tidybayes
  • [ ] https://github.com/kassambara/survminer
  • [ ] https://github.com/GuangchuangYu/ggtree
  • [ ] ggpolypath https://github.com/ropensci/plotly/issues/1339
  • [ ] geomnet
  • [ ] https://github.com/clauswilke/ggjoy
  • [ ] https://github.com/baptiste/ggflags
  • [ ] ggtheme's geom_rangeframe
  • [ ] https://github.com/wilkox/treemapify
    • Seems to have significant overlap with ggraph
  • [ ] directlabels #1244
  • [ ] ggsurv (GeomConfint) #1404
  • [ ] ggimage #1442
  • [ ] statebins https://github.com/ropensci/plotly/issues/1558
  • [ ] corrr https://github.com/ropensci/plotly/issues/1684
    • Does this provide any value over GGally::ggcorr()?
  • [ ] ggpmisc https://github.com/ropensci/plotly/issues/1687
  • [ ] ggnewscale https://github.com/ropensci/plotly/issues/1661
  • [ ] Ipaper https://github.com/ropensci/plotly/issues/1672
  • [ ] qqplotr https://github.com/ropensci/plotly/issues/1705
  • [ ] ggpmisc::stat_poly_eq() https://github.com/ropensci/plotly/issues/1921

Extensions that ggplotly() currently supports

  • [x] GGally
  • [x] ggalluvial
  • [x] ggalt

Extensions that we don't plan on working on anytime soon

  • ggrepel
    • Reasoning: https://github.com/plotly/plotly.R/issues/2018#issuecomment-958146301
  • patchwork, gridExtra
    • Reasoning: https://github.com/plotly/plotly.R/issues/2028#issuecomment-956431432
  • ggtern
    • Reasoning: https://github.com/plotly/plotly.R/issues/2015#issuecomment-958155674

Want to add an extension?

If any community members are interested in implementing a hook into ggplotly() for a custom geom, see https://cpsievert.github.io/plotly_book/translating-custom-ggplot2-geoms.html

If anyone would like to sponsor work on a specific geom/package, please get in touch.

cpsievert avatar Apr 28 '16 12:04 cpsievert

I am working in the forecast package right now and would really like to use Plotly for my dashboard! I have found the following links really helpful for converting forecast to ggplot2 : http://robjhyndman.com/hyndsight/forecasts-and-ggplot/

http://davenportspatialanalytics.squarespace.com/blog/2012/3/14/plotting-forecast-objects-in-ggplot-part-1-extracting-the-da.html

http://davenportspatialanalytics.squarespace.com/blog/2012/3/21/plotting-forecast-objects-in-ggplot-part-2-visualize-observa.html

Although I will admit I think there is a bug with the geom_ribbon function in plotly. I can plot the ggplot perfectly with my prediction band, but the ggplotly interpretation of the ggplot2 is converting my NA's for the observed values into values for the geom_ribbon

ggplot2 image image

ggplotly image

bsquire0128 avatar Jul 08 '16 21:07 bsquire0128

can I just add a huge +1 for ggrepel support via plotly::ggplotly()?

The ggrepel repel-optimisation of course, wouldn't be available in pure JS. Any chance it could be replicated in plotly?

Would be nice to have the repelled-labels resized/react to the size of the plots.

maxheld83 avatar Dec 20 '16 08:12 maxheld83

I'm working on a hook for my fork of ggflags (which substitutes SVGs for the PNGs originally used). I'm trying to get my head around is_basic and geom2trace—in particular, how they fit into the broader plot conversion process and how much I can model one of them on, say, GeomPoint.

EDIT: also documenting as I work things out on Stack Overflow. Any expertise or guidance from people here would be appreciated, though!

jimjam-slam avatar Sep 11 '17 02:09 jimjam-slam

I don't think plotly.js has the ability to accept arbitrary SVG/PNG for marker definitions...you might be able to leverage marker color gradients, but I'm not immediately sure.

Anyway, I remember having a look at ggflags and was thinking we could probably convert them in a similar way to annotation_raster(). Have a look at layers2layout() and let me know you have questions!

cpsievert avatar Sep 11 '17 15:09 cpsievert

Mmmm, I think I see how it works. The main problem I see is that geom_flag isn't an annotation. That means you'd have to manually evaluate its aesthetics to position and size it, and I don't think it would work with facets (I'm also guessing that annotations don't get hovertexts—is that correct?).

jimjam-slam avatar Sep 14 '17 01:09 jimjam-slam

Annotations are raster objects -- that's also true for geom_flag, correct? If so, the implementation would be very similar (which works for facets)

cpsievert avatar Sep 14 '17 16:09 cpsievert

In the case of my fork of ggflags, I've switched to using SVGs in order to size them without blowing out file size. But my concern is less about the file format and more about associating the flags with the source dataset in the way that traces do. I don't want to just decorate the layout with flags; I'm interested in using them as actual points (or at least giving the user that impression).

jimjam-slam avatar Sep 14 '17 23:09 jimjam-slam

Would be super awesome if geom_text_repel() would work with plotly since I mainly use plotly for plots totally crowded with text :+1:

KasperSkytte avatar Oct 30 '17 15:10 KasperSkytte

apparently ggjoy is deprecated in favor of ggridges

flying-sheep avatar Jan 09 '18 18:01 flying-sheep

will love to see ggraph implemented.

about the comment: " treemapify (although, this seems to have significant overlap with ggraph) " it means that i must choose one or the other ? in case both get implemented and i want to use both ?

thanks in advance, and keep the awsome work :D !

jas1 avatar Jun 03 '18 04:06 jas1

I'd love to see geom_dl or geom_text_repel added to ggplotly function. I would also like to see stat_cor supported. It provides an easy way to display significance and correlation values.

I also wanted to add an issue when setting custom themes. Omitting the theme() function results in normal functioning. The error is :

Error in convertUnit(x, unitTo, "y", "dimension", "y", "dimension", valueOnly = valueOnly) : 'x' argument must be a unit object

Example: p2 <- ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point() + geom_smooth(method = "lm", se = F) + theme_tufte() + facet_wrap(~cyl, scales = "free") + theme( panel.background = element_rect(fill = NA, color = "gray"), axis.title = element_text(size = 12, face = "bold"), axis.text = element_text(size = 10, face = "bold", color = "black"), axis.line.x.bottom = element_line(color = "gray"), axis.line.y.left = element_line(color = "gray"), legend.position = "none", strip.text = element_blank() ) p2 ggplotly(p2)

jvschoen avatar Oct 17 '18 19:10 jvschoen

I'd like to second the request for a ggridges implementation.

library(ggridges)
(
  ggplot(diamonds, aes(price, cut)) + 
    stat_binline(bins = 20, scale = .7, draw_baseline = FALSE) +
    theme_ridges()
) %>% ggplotly()
(
ggplot(iris, aes(x = Sepal.Length, y = Species)) +
  geom_density_ridges(rel_min_height = 0.005) +
  scale_y_discrete(expand = c(0.01, 0)) +
  scale_x_continuous(expand = c(0.01, 0)) +
  theme_ridges()
) %>% ggplotly()

ifellows avatar Mar 06 '19 16:03 ifellows

@cpsievert Can you say if there is any active development or planning to support for ggraph anytime soon? Saying "we want to support it" is great, but I wonder what sort of priority is it to you?

geotheory avatar Apr 05 '19 10:04 geotheory

Treemap has just been added to plotly.js See https://github.com/plotly/plotly.js/pull/4185

stephLH avatar Sep 26 '19 11:09 stephLH

Any chance geom_ma() from the tidyquant package will be implemented with ggplotly()?

emmamaury avatar Jun 10 '20 16:06 emmamaury

Any chance geom_stratum() and geom_alluvium() from the ggalluvial package be implemented with ggplotly soon?

shashidhar22 avatar Feb 26 '21 20:02 shashidhar22

would you implement gggenes with ggplotly ?

lozybean avatar Aug 16 '21 09:08 lozybean

@cpsievert can you rank the geoms by importance so I can try implementing them sequentially.

moutikabdessabour avatar Oct 13 '21 22:10 moutikabdessabour

@moutikabdessabour here's some code to get weekly downloads over the past year for all the packages listed thus far. This pretty well reflects my priority list

library(dplyr)
library(cranlogs)
library(plotly)
downloads <- cran_downloads(
  package = c(
  "ggraph", "ggforce", "ggrepel", "ggtern", "tidybayes", "ggtree", "ggpolypath", "geomnet", "ggjoy", "ggflags", "forecast", "survminer", "tidyquant", "ggtheme", "treemapify", "directlabels", "ggsurv", "ggimage", "statebins", "ggpubr", "corrr", "ggpmisc", "ggnewscale", "Ipaper", "qqplotr", "ggpmisc"
), 
  from = Sys.Date() - 365, to = Sys.Date() - 1
)
downloadsTransformed <- downloads %>%
  mutate(count = zoo::rollapply(count, 7, sum, fill = NA))
plot_ly(downloadsTransformed, x = ~date, y = ~count, color = ~package) %>%
  add_lines() %>%
  config(displayModeBar = FALSE) %>%
  layout(hovermode = "x", yaxis = list(title = "Number of downloads"), xaxis = list(title = "", rangeslider = list(visible = TRUE), rangeselector = list(buttons = list(list(count = 1, label = "1m", step = "month", stepmode = "backward"), list(count = 12, label = "1yr", step = "month", stepmode = "backward"), list(step = "all")))))
Screen Shot 2021-11-02 at 4 04 53 PM

cpsievert avatar Nov 02 '21 21:11 cpsievert

As said, ggjoy has been superseded by ggridges, so you should count them together.

flying-sheep avatar Dec 21 '21 08:12 flying-sheep

Can gggenomes be implemented in ggplotly? Thank you!

cms72 avatar Mar 20 '22 10:03 cms72

When I try to use ggplotly(g1), where g1 is a ggplot using directlabels::geom_dl(), I get: I get "geom_GeomDl() has yet to be implemented in plotly."

and no labels on the ggplotly plot.

Fully reported in https://github.com/plotly/plotly.R/issues/1244#issuecomment-1303254365

but #1244 is closed...

aloboa avatar Nov 05 '22 08:11 aloboa