This article describes how to go from a general geographic map:
To a version of your geographic map with an initial zoom and position applied:
A geographic map visualization.
- Select the map visualization on a Page.
- From the object inspector, go to Chart > APPEARANCE > Map package > leaflet.
- OPTIONAL: If you have multiple columns of data in the input table that was used to create the original geographic map visualization, you can indicate which columns to include by updating the COLUMN MANIPULATIONS settings. For example, if I have 3 columns, and only want to show the first column, go to Inputs > COLUMN MANIPULATIONS > Number of columns from left to show and set to "1".
- Show background map for context by ticking Chart > APPEARANCE > Background map.
- Set the color of missing regions to transparent by selecting Chart > APPEARANCE > Color of NA values > More colors > white box with the red X and border.
- Set the shading so that darker red means a lower population using Chart > DATA SERIES > Color palette > Reds, dark to light.
- Access the R code underlying the map by going to Properties > R CODE.
- At the bottom of the R code, load in the leaflet R package with library(leaflet) to get access to the full set of functions to customize the leaflet map.
# load leaflet library
9. Add another line after that, to set the initial position and zoom of the map using the setView function from the leaflet R package. The syntax is as follows:
#Set the zoom to center on a particular coordinate on the map
#Replace YourVisualizationName with the name of your visualization above near "#Creating the chart or table" i.e. viz.1, chart.2, etc
#Replace TheLongitude with the longitude coordinate for the center
#Replace TheLatitude with the latitude coordinate for the center
#Replace TheZoomLevel with the desired zoom from 0 (the world) to 18 (street-level).
YourVisualizationName <- setView(map = YourVisualizationName$htmlwidget, lng = TheLongitude, lat = TheLatitude, zoom = TheZoomLevel)
For example, my code is:
# load leaflet library
# set chart and add longitude, latitude, and zoom levels
chart.50 <- setView(map = chart.50$htmlwidget, lng = -87.6298, lat = 41.8781, zoom = 9)
After your map re-calculates, it will now automatically be zoomed in to your desired area.
- You can tweak your initial zoom level by using decimals, such as 1.5.
- To find the latitude and longitude to center your map you can:
- Click on a blank spot on a Google map. A small window at the bottom of the screen will display the coordinates.
- Google "YourCity/State/Country lat long", and use coordinates from the results.
- Use a website such as https://www.latlong.net/ to find the coordinates.