The Battle of Interactive Geographic Visualization Part 1 — Interactive Geoplot Using One Line of Code | by Francis Adrian Viernes | Towards Data Science

Geospatial data is probably one of the most complex forms of data that currently exists. For one reason, this form of data is not used in the usual conversations between analysts. For example, analysts do not usually talk about latitude and longitude, and/or, shapefiles.
For another reason, the pattern exhibited by geospatial data is not easily apparent.
As such, geovisualization plays an important role in the preliminary analysis and design of research.
Geo-scatter plots are like normal scatterplots except that they use the geocode (location) of observation as the base of reference in mapping. This means that as opposed to a normal scatterplot that has the x and y variables (rational numeric type), the x and y for a geo-scatter plot are longitude and latitude and are nominal.
Geo-scatter plots have been more popular recently due to the efforts of data scientists to track COVID-19 infections.
In this article series, we’ll make use of the same dataset but with a different package.
The dataset that we are going to use is the “Philippines Coffee Shops Footprint” dataset which I have generated last 2020 to map out the Google-maps-listed coffee shops in the Philippines.
The process of generating this data is as follows: https://towardsdatascience.com/mapping-your-favorite-coffee-shop-in-the-philippines-using-google-places-api-and-folium-2f9d5ad697bf
import pandas as pddf = pd.read_csv('data/Coffee Brands Footprint.csv',                index_col=0)df.head()
Note that for plotting geospatial graphs, it is important to have a column for longitude and latitude. In some cases, you may replace this with a GeoPandas geometric object (point, lines, polygon).
Without further adieu, let’s begin.
Holoviews is one of the high-level plotting packages out there currently. It’s very easy to use and for those who are strapped for time, I recommend this package.
pip install holoviews
Note Ensure to install the geoviews package as well.
pip install geoviews
A geoscatter plot can be generated using this one line of code:
df.hvplot.points(    x='lng', #longitude column    y='lat', #latitude column    hover_cols=['vicinity'], #tooltip when hovered over    c='brand', #color argument    title='Coffee Shops in The Philippines',     geo=True,    tiles='CartoLight')
Notice that it is just like plotting a normal scatterplot! And just as our introduction stated, the x and y parameters pertain to longitude and latitude columns.
The argument of geo=True is important for holoviews to interpret the x and y variables as forming the geocode.
Let us remove the frame as well as it may not be visually appealing. This can be accomplished by setting xaxis and yaxis as None.
df.hvplot.points(    x='lng',     y='lat',    frame_height=1000,    frame_width=500,    xaxis=None,    yaxis=None,    hover_cols=['brand', 'vicinity'],     c='brand',     title='Coffee Shops in The Philippines',     geo=True,    tiles='CartoLight')
Because of the overlapping points, it’s difficult to see just how many stores are in a particular area. What helps in this situation is setting the transparency of the points to less than 100%.
For these cases, we can try to set it to 30% with the keyword alpha=0.3.
df.hvplot.points(    x='lng',     y='lat',    alpha=0.3,    frame_height=1000,    frame_width=500,    xaxis=None,    yaxis=None,    hover_cols=['vicinity'],     c='brand',     title='Coffee Shops in The Philippines',     geo=True,    tiles='CartoLight')
Aside from the fact that holoviews is easy to use and understand, the graph we have generated above can be deployed as a webpage which you can use for a presentation.
A lot of our executives would prefer not to see the raw codes so deploying this as a separate webpage when reporting is a big plus.
To deploy as a separate page:
import panel as pnimport holoviews as hvimport holoviews.plotting.bokehpn.panel(geoscatter).servable(title='HoloViews App').show() #.show() makes it to be a separate html
One disadvantage, as with most packages, is that the customization may not be as comprehensive when compared to other packages such as Folium.
There are a lot of customizations that we can do to improve the visualization that we already have above. For readers interested in continuously improving the geo-scatter, the following are recommended:  1. Choose a Customized Color Palette — Particularly, what we have above are Coffee Brands and these can be associated with a particular color. For example, Starbucks has a particular color of green that can identify the brand well. The suggested approach here is to create a column for brands' colors where this column is supplied to the c or color parameter.
2. Try a different tile— For graphs with a lot of different colors (non-monotonic), it is ideal that the tiles are less-colorful to emphasize the points. For monotonic colors, applicable for continuous variables, colorful graphs can be used cautiously. The main idea is that the tile should not distract or take away from one glance the message of the geo-plot, which is the point of why we are doing this anyway.
As you can see from what we have above, visualizing the points elevates our understanding of geospatial data. Patterns, such as those of the network effects, are readily available and we can probably infer that the more coffee shops in the area are, the more developed that place is.
We’ll try a different package in the next series to compare the overall syntax and aesthetics.
Full code on my Github page.
Let me know what you think!