Dot and Dumbbell Plots
library(plotly) s <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv") s <- s[order(s$Men), ] fig <- plot_ly(s, x = ~Women, y = ~School, name = "Women", type = 'scatter', mode = "markers", marker = list(color = "pink")) fig <- fig %>% add_trace(x = ~Men, y = ~School, name = "Men",type = 'scatter', mode = "markers", marker = list(color = "blue")) fig <- fig %>% layout( title = "Gender earnings disparity", xaxis = list(title = "Annual Salary (in thousands)"), margin = list(l = 100) ) fig
See https://plotly.com/r/reference/#scatter for more information and chart attribute options!
What About Dash?
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) fig <- plot_ly() # fig <- fig %>% add_trace( ... ) # fig <- fig %>% layout( ... ) library(dash) library(dashCoreComponents) library(dashHtmlComponents) app <- Dash$new() app$layout( htmlDiv( list( dccGraph(figure=fig) ) ) ) app$run_server(debug=TRUE, dev_tools_hot_reload=FALSE)