The Example
<- data.frame(
df x = c(1,2,3),
y = c(1,2,3),
f = c(1,2,3)
)
<- df %>%
fig plot_ly(
x = ~x,
y = ~y,
frame = ~f,
type = 'scatter',
mode = 'markers',
showlegend = F
)
fig
Mulitple Trace Animations
<- gapminder
df1 <- df1 %>%
fig plot_ly(
x = ~gdpPercap,
y = ~lifeExp,
size = ~pop,
color = ~continent,
frame = ~year,
text = ~country,
hoverinfo = "text",
type = 'scatter',
mode = 'markers'
)<- fig %>% layout( # To make the scale of Xasis is log
fig xaxis = list(
type = "log"
)
)
fig
Add Animation Options
<- fig %>%
fig animation_opts(
frame = 1500, easing = "sin", redraw = FALSE #The higher value of frame make the animation becomes slower
# Easing for the transition
) #Easing can be: linear, elastic, quad, quad-in, cubic, sin, exp...
fig
Add Slider Options
<- fig %>%
fig animation_slider(
currentvalue = list(prefix = "Year ", font = list(color="#00adef"))
)
fig
Dash for R
Dash for R is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.
Learn about how to install Dash for R at https://dashr.plot.ly/installation.
Everywhere in this page that you see fig
, you can display the same figure in a Dash for R application by passing it to the figure
argument of the Graph
component from the built-in dashCoreComponents
package like this:
library(plotly)
<- plot_ly()
fig # fig <- fig %>% add_trace( ... )
# fig <- fig %>% layout( ... )
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
<- Dash$new()
app $layout(
apphtmlDiv(
list(
dccGraph(figure=fig)
)
)
)
#app$run_server(debug=TRUE, dev_tools_hot_reload=FALSE)