plotly / plotly/plotly.R

Implement geom_GeomFunction()

Open
#1,887 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

I am running an R shiny app that uses plotly. One of the plots includes a distribution drawn using stat_function, which works great with ggplot(), but that dissapears when the ggplot object is passed to plotly::ggplotly(), returning the following message:

Warning message:
In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_GeomFunction() 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

Please, follow the reproducible example below, using the attached file (see below) as input:

library("plotly")
library("tidyverse")
df <- readr::read_csv("effect.csv")
my_plot <- df %>% ggplot2::ggplot() +
    stat_bin(aes(x=effect, y=..density..), fill="blue", colour="white", binwidth = 0.02) +
    stat_function(aes(x = effect, y = ..y..), fun = get("dlnorm"), colour="red", n = 100, args = c(-3.3, 0.5)) +
    scale_x_continuous(name = "Effect size") +
    scale_y_continuous(name = "", limits = c(0, 25))
    theme_minimal()
# ggplot (with the red line showing the distribution fit)
my_plot
# plotly version (without the line, and returning the above message)
plotly::ggplotly(my_plot)

Example file with effect.csv:
example.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the geom2trace.default warning produced by plotly::ggplotly() and reproduce it using the supplied R example and effect.csv file. Compare the ggplot and plotly outputs for stat_function with dlnorm. Done means the distribution line appears in the plotly output and the unimplemented-geom warning is gone.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.