Open cpsievert opened 8 years ago
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/
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
ggplotly
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.
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!
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!
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?).
Annotations are raster objects -- that's also true for geom_flag, correct? If so, the implementation would be very similar (which works for facets)
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).
Would be super awesome if geom_text_repel() would work with plotly since I mainly use plotly for plots totally crowded with text :+1:
apparently ggjoy is deprecated in favor of ggridges
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 !
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)
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()
@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?
Treemap has just been added to plotly.js See https://github.com/plotly/plotly.js/pull/4185
Any chance geom_ma()
from the tidyquant package will be implemented with ggplotly()
?
Any chance geom_stratum()
and geom_alluvium()
from the ggalluvial
package be implemented with ggplotly
soon?
@cpsievert can you rank the geoms by importance so I can try implementing them sequentially.
@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")))))
As said, ggjoy has been superseded by ggridges, so you should count them together.
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...
Extensions that we'd like
ggplotly()
to supportggpubr::stat_compare_means()
(and maybe others from https://github.com/kassambara/ggpubr?)GGally::ggcorr()
?ggpmisc::stat_poly_eq()
https://github.com/ropensci/plotly/issues/1921Extensions that
ggplotly()
currently supportsExtensions that we don't plan on working on anytime soon
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.htmlIf anyone would like to sponsor work on a specific geom/package, please get in touch.