title | name | permalink | description | layout | thumbnail | language | page_type | has_thumbnail | display_as | order | output | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Extending ggplotly | Examples | Plotly |
Extending ggplotly |
ggplot2/extending-ggplotly/ |
How modify the plotly object after ggplot2 conversion. |
base |
thumbnail/extending_ggplotly.png |
ggplot2 |
example_index |
true |
fundamentals |
1 |
|
Plotly's R library is free and open source!
Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode.
We also have a quick-reference cheatsheet (new!) to help you get started!
Version 4 of Plotly's R package is now available!
Check out this post for more information on breaking changes and new features available in this version.
library(plotly)
packageVersion('plotly')
## [1] '4.7.1.9000'
library(plotly)
p <- ggplot(fortify(forecast::gold), aes(x, y)) + geom_line()
gg <- ggplotly(p)
gg <- style(gg, line = list(color = 'gold'), hoverinfo = "y", traces = 1)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(gg, filename="extending/style")
chart_link
library(plotly)
p <- ggplot(fortify(forecast::gold), aes(x, y)) + geom_line()
gg <- ggplotly(p)
gg <- plotly_build(p)
gg$x$data[[1]]$line$color <- 'blue'
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(gg, filename="extending/build")
chart_link
library(plotly)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() + geom_smooth()
p <- p %>%
ggplotly(layerData = 2, originalData = F) %>%
add_fun(function(p) {
p %>% slice(which.max(se)) %>%
add_segments(x = ~x, xend = ~x, y = ~ymin, yend = ~ymax) %>%
add_annotations("Maximum uncertainty", ax = 60)
}) %>%
add_fun(function(p) {
p %>% slice(which.min(se)) %>%
add_segments(x = ~x, xend = ~x, y = ~ymin, yend = ~ymax) %>%
add_annotations("Minimum uncertainty")
})
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="extending/layerdata")
chart_link
For more information concerning modidfying the plotly object see The Plotly Book