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

Mapbox Access Token

To create mapbox maps with Plotly, you'll need a Mapbox account and a Mapbox Access Token that you can add to your Plotly Settings. If you're using a Plotly On-Premise server, please see additional instructions here: https://help.plot.ly/mapbox-atlas/.

Add Polygon to a Map Projection

library(plotly)geo<-list(scope='usa',showland=TRUE,landcolor=toRGB("gray95"),countrycolor=toRGB("gray80"))p<-cali_pop%>%group_by(group)%>%plot_geo(x=~long,y=~lat,color=~pop_cat,colors=c('#ffeda0','#f03b20'),text=~subregion,hoverinfo='text')%>%add_polygons(line=list(width=0.4))%>%add_polygons(fillcolor='transparent',line=list(color='black',width=0.5),showlegend=FALSE,hoverinfo='none')%>%layout(title="California Population by County",geo=geo)# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link=api_create(p,filename="county-level-geo")chart_link