Requirements
In this homework, you will learn to create maps with Plotly.
1. You will create 5 maps. Each map is worth 20 points.
2. You must use Plotly Express or Plotly API to create the charts.
Do not use Plotly Chart Studio.
3. Load election_context-2018.csv and use Plotly to create the following maps. Each map must have a title and legend.
a. (Figure 1) A Choropleth map showing the 2016 county by county
senate
election results in the state of
Georgia. The map should show the map of Georgia and only Georgia.
i. For each county, compare the columns “demsen16”, “repsen16”, and “othersen16”.
If “demsen16” has the highest number, color the county blue in the map.
If “repsen16” has the highest number, color the county red in the map.
If “othersen16” has the highest number, color the county white in the map.
ii. The border of each county should be black.
b. (Figure 2) Create a similar Choropleth map showing the 2016 county by county
house
election results in the state of
Georgia, using the same color scheme as specified above.
c. (Optional, 10 bonus points) Create a Plotly Dash application that has three drop down menus: “year”, “state”, and “election category”. In the “election category”, a user can select “senate” or “house”. The data visualization should be automatically updated to display the map (Figure 1 and Figure 2) based on the options selected.
4. Load 1976-2018-senate.csv and use Plotly to create the following map. Every figure must have a title and a legend.
a. (Figure 3) Create a Choropleth map for the
2018
US senate election. The map should show the entire United States. Each state should be color coded. The value for each state is the winning candidate’s vote percentage. Divide the vote percentage into 6 bins and create a color scale for it.
When the mouse cursor hovers over each state, the winning candidate’s name and party affiliation should be displayed in the tooltip window. For example, Wyoming’s 2018 winning candidate was John Barrasso, Republican. His vote percentage was 136210/203420.
5. Load 1962_2006_walmart_store_openings.csv and use Plotly to create the following map. The map must have a title and legend.
a. (Figure 4) Create a Scattergeo map that shows the location of every Walmart store opened since
2000
(including 2000) in the United States.
b. The map should show the entire United States.
c. If it’s a “Supercenter”, use a dark blue color to fill the marker. If it’s a “Wal-Mart”, use a light blue color.
6. Load wimbledons_champions.csv and use Google Maps Services Python client to create the following map.
a. (Figure 5) Create a map showing the number of champions for different countries.
b. The map should show the entire world.
c. Calculate how many Wimbledon champions each country has produced.
d. Place a marker for each country that has produced a champion. Use the latitude and longitude of the capital of the country as the location.
i. You will need to find the latitude and longitude for the capitals yourself.
e. The size of the marker should be proportional to the number of champions this country has produced.
7. Write your code in Jupyter Notebook. Submit both your Jupyter Notebook file (or Python code) and a PDF file or HTML file.
a. To download your Jupyter Notebook as PDF, you'll need to install MikTeX (https://miktex.org/download) fist.
b. Another option is to export/download the notebook to HTML and then convert it to PDF. However, I understand the charts may be cut off during this process.
c. You can also export your data visualizations as pictures. Please see my lecture notes for instructions.
d. The PDF or HTML file must contain all the data visualizations. If you submit files without any data visualization, even if your Python code is correct, you will lose half of the credit.
e. Your Jupyter Notebook and the PDF file should be of the following format:
i. Markdown cell: question number (e.g. Question 1.a) and the requirements
ii. Code cell: your Python code.
iii. Output: the data visualization
iv. Repeat the above pattern for each requirement.
f. . If Jupyter Notebook doesn’t work, you may use Spyder. But you still need to create a PDF file that follow the above pattern: question number/requirements, Python code, data visualization, …
g. Please refer to the syllabus for late submission policies.