ggplotly | R Documentation |
This function converts a ggplot2::ggplot()
object to a
plotly object.
ggplotly(
p = ggplot2::last_plot(),
width = NULL,
height = NULL,
tooltip = "all",
dynamicTicks = FALSE,
layerData = 1,
originalData = TRUE,
source = "A",
...
)
p |
a ggplot object. |
width |
Width of the plot in pixels (optional, defaults to automatic sizing). |
height |
Height of the plot in pixels (optional, defaults to automatic sizing). |
tooltip |
a character vector specifying which aesthetic mappings to show
in the tooltip. The default, "all", means show all the aesthetic mappings
(including the unofficial "text" aesthetic). The order of variables here will
also control the order they appear. For example, use
|
dynamicTicks |
should plotly.js dynamically generate axis tick labels? Dynamic ticks are useful for updating ticks in response to zoom/pan interactions; however, they can not always reproduce labels as they would appear in the static ggplot2 image. |
layerData |
data from which layer should be returned? |
originalData |
should the "original" or "scaled" data be returned? |
source |
a character string of length 1. Match the value of this string
with the source argument in |
... |
arguments passed onto methods. |
Conversion of relative sizes depends on the size of the current
graphics device (if no device is open, width/height of a new (off-screen)
device defaults to 640/480). In other words, height
and
width
must be specified at runtime to ensure sizing is correct.
For examples on how to specify the output container's height
/width
in a
shiny app, see plotly_example("shiny", "ggplotly_sizing")
.
Carson Sievert
plot_ly()
## Not run:
# simple example
ggpenguins <- qplot(bill_length_mm , body_mass_g,
data = palmerpenguins::penguins, color = species)
ggplotly(ggpenguins)
data(canada.cities, package = "maps")
viz <- ggplot(canada.cities, aes(long, lat)) +
borders(regions = "canada") +
coord_equal() +
geom_point(aes(text = name, size = pop), colour = "red", alpha = 1/2)
ggplotly(viz, tooltip = c("text", "size"))
# linked scatterplot brushing
d <- highlight_key(mtcars)
qplot(data = d, x = mpg, y = wt) %>%
subplot(qplot(data = d, x = mpg, y = vs)) %>%
layout(title = "Click and drag to select points") %>%
highlight("plotly_selected")
# more brushing (i.e. highlighting) examples
demo("crosstalk-highlight-ggplotly", package = "plotly")
# client-side linked brushing in a scatterplot matrix
highlight_key(palmerpenguins::penguins) %>%
GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
ggplotly(tooltip = c("x", "y", "colour")) %>%
highlight("plotly_selected")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.