Version Check

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.0'

Dot and Dumbbell Plots

s<-read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")# order factor levels by men's income (plot_ly() will pick up on this ordering)
s$School<-factor(s$School,levels=s$School[order(s$Men)])library(plotly)p<-plot_ly(s,color=I("gray80"))%>%add_segments(x=~Women,xend=~Men,y=~School,yend=~School,showlegend=FALSE)%>%add_markers(x=~Women,y=~School,name="Women",color=I("pink"))%>%add_markers(x=~Men,y=~School,name="Men",color=I("blue"))%>%layout(title="Gender earnings disparity",xaxis=list(title="Annual Salary (in thousands)"),margin=list(l=65))# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link=api_create(p,filename="dumbell-plots/income")chart_link