plotly
package in R
is an advanced tool for creating
interactive and high-quality visualizations. It enhances the visual appeal and user
interaction of your graphics, making the data exploration process more insightful.
plotly
package supports a wide range of charts and plots
and works seamlessly
with ggplot2
graphics through the ggplotly()
function, converting
static ggplot2 plots into interactive Plotly graphics.
plotly
and
ggplotly()
are used to enhance ggplot2
charts. ggplotly()
to bring your data visualizations to life.
ggplotly()
is all you needThe ggplotly()
function takes a
ggplot2 graphic as argument and returns an interactive version of it. This means you can make your graphics
interactive with a single line of code!
Bear in mind, however, that the plotly package has other functionalities. Plotly has its own native
syntax for creating interactive graphics from scratch that relies on the plot_ly()
function.
In practice, this is useful when you want access to a very precise level of customization and/or to
create graphics not supported by ggplot2 (which is uncommon but not impossible).
The most awesome feature of plotly
is its ggplotly()
function. If you know how to make a ggplot2
chart, you are 10 seconds away to rendering an interactive version. Just call the ggplotly()
function, and you’re done. Visit the interactive graphic section of the gallery for more.
library(ggplot2) library(plotly) library(gapminder) p <- gapminder %>% filter(year==1977) %>% ggplot( aes(gdpPercap, lifeExp, size = pop, color=continent)) + geom_point() + theme_bw() ggplotly(p)
← this chart is interactive: hover, drag, zoom, export and more.
Interactivity has a major role in data visualization. It allows to focus on specific parts of the chart, to zoom in and out and to explore your data.
In the gallery, you can find many examples illustrating the ggplotly()
function of the plotly
library. Here they are:
You can customize the tooltip of your ggplotly()
chart. This is done by using the tooltip
argument of the ggplotly()
function. Here is an example using the gapminder dataset:
plotly
Plotly has its own native syntax for creating interactive graphics from scratch that relies on the plot_ly()
function. It creates really nice charts too in just a few lines!
plot_ly()
.