Filtered Point Map with Socrata
Socrata is a database service that is used by government agencies, cities and countries to make open data available to the public. It offers user-friendly ways to view, filter, and export data. In addition, the Socrata platform includes built-in support to create interactive charts and maps, which can be embedded in other websites (including your own).
One advantage of creating data visualizations directly on an open data platform is that the chart or map is linked to the data repository. For example, if the Socrata platform administrator updates the data table, then a Socrata dataviz based on that data will be automatically updated, too. This may be especially useful for “live” data that is continuously updated by agency administrators such as fires, crimes, and property data.
Generally, in order to create a map in Socrata, you need to be a registered user,
and the dataset you wish to visualize has to contain a column with location data.
This is not just an address column (such as
3500 Gaston Avenue, Dallas, TX), but
a geocoded column that contains latitude and longitude values.
Sign Up for Socrata Account
Navigate to Data.Medicare.gov click Sign In button in the upper-right corner. Scroll down to Sign Up link. Follow the instructions, including setting up two-step authentication, to create a free account.
Note: You can still practice creating a map in Socrata without being logged in. You won’t be able to save or share it, however.
Once you have an account, log in using your credentials. Navigate to your profile by clicking your username in the upper-right corner and make sure you Accept Terms and Conditions, otherwise you won’t be able to save your draft map.
This username and password are only valid for Data.Medicare.gov, not other websites that use Socrata.
Create Your First Socrata Point Map
Navigate to the Hospital General Dataset, and in the menu on the right-hand side choose Visualize > Launch New Visualization, as shown in Figure 6.20. This will open up a Configure Visualization studio where you can create the map.
In the top menu, click Map (globe icon between a scatter chart icon and a calendar). You will see an updated layout of the studio, with the map in the middle, and Map Layers and Map Settings items in the side menu on the left.
Socrata was able to determine which column contains geospatial value, and automatically
set Geo Column value to Location in the Layer List menu. By default, points are clustered (grouped together),
so instead of seeing individual hospital locations, you see bubbles with numbers (such as
12 in Alaska).
Let’s first select only hospitals that are located in the southern state of Texas. To do so, go to Filters > Add filter. The dropdown menu lists all columns (or fields) of the dataset, where we should choose State. In the newly appeared State dropdown, choose TX (for Texas) as shown in Figure 6.21, and scroll down and click Apply. Socrata should zoom in on the map and center on Texas. Close Filters window to free screen space.
Let’s now disaggregate the map so that we can see individual hospitals instead of clusters. Go to Map Settings > Cluster, and bring the Stop Clustering at Zoom Level slider to 1, as shown in Figure 6.22. You will see the map now shows individual points.
In the same accordion menu, change Basemap > Type to Dark to bring the map a fashionable 2020 look. In General, set Title to Texas Hospitals, and hide data table below the map by unchecking the Show data table below visualization box. Under Map Controls, uncheck Show Search Bar and Show Locate Button to get rid of unnecessary elements. Feel free to experiment with other settings as well.
Now, let’s return back to Map Layers menu and choose our Hospitals General Information point layer. You can notice that in Data Selection accordion menu, Resize Points by Value is grayed out. That is because the dataset doesn’t contain columns with continuous variables that can be transformed to point sizes. Instead, we can use Style by Value option to classify categorical points. The dataset contains multiple variables that can be effectively visualized, such as Hospital Type, Emergency Services (a yes/no category), Mortality national comparison and others. Let’s stick with Hospital Type, as is illustrated in Figure 6.23.
If you look at the bottom-right corner of the map, you should notice a minimized Legend control. Click on it to see what each color represents.
Change the color palette (in Color menu) from Categorical 1 to Categorical 2, which includes a wider range of unique colors. You can also use Custom… item to set individual colors, as well as change the order of categories in the legend.
To change what is shown in tooltips when you hover or click on points, go to Flyout Details, and set Flyout Title to Facility Name, adding city and phone number as additional flyout values, as is shown in Figure 6.24.
At this point you should have a fully-functional interactive map showing all hospitals in Texas, colored according to their type. Before you can share it, you need to save it as a draft, and publish.
Save Draft and Publish
In the lower-right corner, click Save Draft button. Give your map a name, and hit Save. The gray ribbon at the top will tell you it is still a draft, and you can go ahead and Publish… it.
Now you can embed the map on your website as an iframe. To do so, click the Share button in the upper-right side of your map (see Figure 6.25), and copy the generated code from Embed Code text area (Figure 6.26). See Chapter 7 of this book for further instructions about embedding.
Limitations of Socrata
But there are limitations to creating your chart or map on an open data repository platform. First, if the agency stops using the platform, or changes the structure of the underlying data, your online map (or chart) may stop functioning. Second, you are generally limited to using datasets and geographic boundaries that already exist on that platform.
If these limitations concern you, a simple alternative is to export data from the open repository (which means that any “live” data would become “static”), and import it into your preferred dataviz tool, such as Tableau.
A second, more advanced alternative, is to learn to pull live data from Socrata using an API (Application Programming Interface). That requires coding skills that are beyond the scope of this book. Visit the official documentation to learn more about Socrata API.