I’m trying to switch from RShiny to Dash and I have some trouble with recreating pretty basic map stuff in Plotly.
I want to make scattermap on top of a layer of custom choropleths (neighbourhoods in NL). These choropleths have a value that is the sum of an attribute of the points in a scatter layer.
Is there an option, like there is for instance in leaflet, to make a scatterplot layer and a custom choropleth layer from a panda’s geodataframe and overlay them on a basemap? See the example below, made with R and Leaflet:
I’ve seen some examples of adding rasters in the layers component of the layout, but I haven’t seen a working example with choropleth and scatterplot layers and it seems like you don’t have as much control over the second layer if you do it this way.
choropleth_data = {
# Your choropleth data here
}
scatter_data = {
# Your scatter data here
}
figure = {
"data": [
choropleth_data,
scatter_data
]
"layout": {
# Your layout dictionary here
}
}
Hello. Having a lot of difficulty with this as well. Surprised there’s not a lot I can find on Google. Currently the Jupyter link doesn’t work (@empet). Also, I’m not really sure how to use @sjtrny’s example using R.
To define a go.Figure() that contains both a chroplethmapbox and a scattermapbox, proceed as follows:
fig = go.Figure(go.Chroplethmapbox()) # here you set all attributes needed for a Choroplethmapbox
fig.add_scattermapbox(lat = your_list_of_latitudes,
lon = your_list_of_longitudes,
mode = 'markers+text',
text = some_text, #a list of strings, one for each geographical position (lon, lat)
below='',
marke_size=12, marker_color='rgb(235, 0, 100)'))
fig.update_layout((title_text ='Your plot title', title_x =0.5,
mapbox = dict(center= dict(lat=52.370216, lon=4.895168), #change to the center of your map
accesstoken= "your-mapbox-access-token",
zoom=6, #change this value correspondingly, for your map
style="light" # set your prefered mapbox style
))
@joeflack4
Unfortunately you posted your question within an old thread under plotly.py category. I don’t work with R, hence I cannot suggest any solution. I’m sorry!!
Here is the documentation for Plotly R, and this section has examples of maps with scatter plots. If this doesn’t answer your question you could try creating a new topic using the R tag.
Hi there, so this helps and was able to overlay points over a set of boundaries. But i also intend to be able to select points by drawing polygon or lasso select , the app breaks in case i try lasso select.