For this first exercise you will be examining how you can use various software for geospatial analysis and graphical display of spatial data. Because of the variety and availability of operating systems in use today, each of the exercises in this course can be completed in either ArcGIS Pro, QGIS, or R. Each of these software have their pro’s and con’s but for simplicity purposes here is a table that might suggest which software would be best for you:
ArcGIS Pro | QGIS | R |
---|---|---|
Available on Windows PC Only | Available for PC, Mac, or Linux (limited) | Available for PC, Mac, Linux, ChromeOS, iOS, or Android via web modern browser |
Available by subscription only | Open Source | Open Source |
Graphical User Interface with built-in functionality for Python; add-ons available for statistical languages | Graphical User Interface with built-in functionality for Python; use of plug-ins for other languages and analyses | Scripting language, mostly used for statistical purpose; packages expand its use to other applications such as geospatial analyses |
Widely used in academia, government, and industry jobs | Widely used in academia and industry | Predominantly used in academia, research, and specialized industry jobs |
Help available at ESRI.com and through various outlets via a google search | Help available at QGIS.org and through sites like stackoverflow.com or other sites via google search | Help available through individual package documentation and sites like stackoverflow.com or other sites via google search |
For the purposes of this course, you can complete the laboratory exercises in any of these software. There will be drop-down menus in every lab color-coded for the three software. Ultimately, you will have access to all of this material during and after the course and while the steps might be different between each version the outcomes will be the same. So if you choose to complete the course with one software you can always go back and complete the work in another software in your own time.
While all of the software will be available on the computers in McCord 210, if you choose to use ArcGIS Pro you will need to contact the APSU GIS Center with your student information to obtain a one year license for your personal computer. QGIS is available for download using this link. If you are completing the course in R you will not need to install any software, however you will need a Google account and access to the Chrome browser. When using R you will be completing all of the lab exercises in the Google Colaboratory and will access everything you need from the exercise pages on GitHub.
More information for each software and the steps to complete this exercise can be found below. Be sure to follow the color-coded drop-down for the specific software you are using for the lab.
ArcGIS Pro is a proprietary software from ESRI. Student access is available in McCord 210 and several other computer labs on campus. If you wish to obtain the software for use on your personal computer (Windows-based PC only) you will need to contact the APSU GIS Center at 601 N 2nd St, Clarksville, TN 37040, (931) 221-7500. Please have your APSU student ID and A# available for verification prior to obtaining a license. Please contact the GIS Center if you have any issues downloading or installing the software.
If you will be using QGIS for the exercises you will need to have the software installed on your computer. QGIS is available for PCs, Mac, and Linux computers. You can find the appropriate download for your operating system here:
When installing on macOS for the first time you may need to go to Systems Preferences > Security and Privacy and on the General tab “Allow apps downloaded from” App Store and identified developers and click Open Anyway. Please contact your instructor if you have any issues downloading or installing the software.
You will be completing the R portion of each exercise using the Google Colaboratory Executable Environment. Colaboratory, or “colab” for short, is based on the popular Jupyter Notebooks and allows you to write and execute R or Python in your browser, with:
Each colab notebook is separated into code cells and text cells. A code cell is used to write and execute a script interactively. Each text cell uses simple markdown syntax for creating plain text information. You can easily share the notebook like other Google Drive based documents by clicking the “Share” link in the upper right-hand portion of the window.
Before beginning each exercise using R, you will need to open the Exercise Colab Notebook and alter the URL to view/edit the file in colab. To do this you will navigate to the exercise’s GitHub page; in this case https://github.com/chrismgentry/GIS1-Exercise-2. In the list of folders and files you will find a file that will always be identified as GIS1_EX followed by the exercise number and a .ipynb file extension. So for this exercise it will be GIS1_EX2.ipynb
When you locate the file, click on the name to open the
ipy notebook. In the resulting window, click on the URL and
insert tocolab immediately after github in the
address. So the new URL for this exercise should now read:
https://githubtocolab.com/chrismgentry/GIS-Exercise-2/blob/main/GIS1_EX2.ipynb
Click enter/return and the file should now open inside of
Colab. Your screen might have a slightly different appearance,
but you should see the Exercise 2, GIS 1 header indicating you are in
the correct notebook.
Each time you open these colab notebooks, or if you have not
interacted with the notebook for an extended period of time, you will
need to make sure the environment is connected and all of the sample
script has been run. To do this go to Runtime > Run all (or
click CRTL+F9) and run the notebook. This may take a moment to complete
so be patient until the last code cell has been executed. You should see
a green check mark with an allocation of RAM and Disk as shown by
horizontal bars which will indicate you are connected. In each section
of code there is a Run cell
button that will allow you to run the individual code cells. This button
will have a rotating loading symbol
while the code cell is being executed. Once it is complete the box will
return to the run state and there may be an output visible depending on
the script. You can add your own text or code cells to a notebook simply
by moving your cursor slowly over the notebook to reveal the code/text
option bar or by going to Insert > Code cell/Text cell.
By clicking within each code or text cell you can edit the
contains and adjust the properties using the various preset option
controls.
You should practice adding and removing cells, editing their
content, and rearranging the order of the cells. This will help
familiarize you with notebook tools and allow you to manipulate
notebooks in these exercises and create your own notebooks in the
future.
For each new exercise there will be a colab notebook available. Within the notebook will be sample code for you to run, code cells for you to complete as part of the exercise and questions to be answered within labeled text cells. Detailed directions will be available on the individual exercise webpage. Each completed exercise will have completed code and question sections and the notebook link shared for a grade.
The Tennessee Valley Authority (TVA) and Tennessee Department of Environment and Conservation (TDEC) are considering a partnership to increase the number of electric vehicle charging stations across the state. With destinations such as Nashville, Memphis, Gatlinburg and the Great Smoky Mountains, Bristol Motor Speedway, Signal Mountain and the Tennessee Aquarium, tourism is a major part of the state’s economy. So accommodating residents and visitors with electric vehicles as well as creating a network for those traveling the states major interstates (I-65, I-40, I-24, I-75, etc.) is of utmost importance.
TDEC says this network of charging stations will also promote electric vehicle growth by giving drivers confidence they will have easy access to refueling while away from home, eliminating so-called “range anxiety” that keeps many consumers from considering electric vehicles as viable transportation. TVA says electric vehicle adoption will spur jobs and economic investment in the region, keep refueling dollars in the local economy, reduce the regions largest source of carbon emissions, and save drivers and fleets money.
So TVA and TDEC have asked you to develop a map showing the number of public electric vehicle charging stations in the continental United States. This will help them understand what the nations current infrastructure looks like and how Tennessee currently compares to neighboring states. It will also help TVA and TDEC determine approximately how many additional stations they should add.
In this exercise you will:
Software specific directions can be found for each step below. Please submit the answer to the questions and your final map by the due date.
In this step you will learn how to obtain data, load it into the software, examine the attributes, and make a simple display.
The purpose of this exercise is to help familiarize you with the ArcGIS Pro program. With this software, you will have the ability to view, create, and edit geographic data, query spatial data, examine spatial relationships, and create publishable maps. To launch ArcGIS Pro, click on the start menu and search for the ArcGIS Folder. Within the folder click on the ArcGIS Pro icon to open.
After the initial splash screen, you’ll be greeted with a screen that allows you to open previous recently saved projects, new map templates, and view various resources from ESRI. For this exercise you will begin by clicking Map under the New > Blank Templates section in the middle of the screen.
This will open a new Create a New Project screen that will ask you to give your new project a name and a location on your computer to save the project. At this point I would recommend creating a folder somewhere on your PC to store all of your GIS1 exercises. If you are in a GIS class using a networked folder, be sure to have that folder mapped and save all of your data under the project folder for this exercise. This will make them easier to locate later on.
After establishing the project, a project file and several folders will be created in your folder, and your screen should appear similar to this:
While your screen might appear slightly different, you should have a basemap in the center section, a list of objects under Map in the Contents section on the left (frequently called a table of contents), and possibly a blank section on the right. For this exercise you will need to download the Electric Vehicle Charging Station data from the GitHub Repository by clicking on the download button at this link and saving it in your exercise folder created above. Once the download is complete you will need to unzip the file by using right-click > extract all on the zipped folder.
This data should now be available for use in your project. To add the information to your map project, navigate to the Map tab on the menu bar and find the Add Data button. From here you can click the drop-down menu and see all of the options. For this example you will click Data, Add data to the map.
Similar to other PC-based GUI interfaces, a new window will open where you will navigate to your data folder and double-click or single-click and click OK to add the data.
This will add the data to your map and it will appear in the table of contents. Your screen should now look similar to the one below (colors may vary):
With this dataset added, you can now begin to explore some of the basic tools for navigating and analyzing the map data. Some information or tools are available in the map view while some are located in each of the various tabs (Map, Insert, Analysis, View, Edit, Imagery, and Share). Additionally, some tabs or information will only become available when data is selected. For example, while on the Map tab, if you select the ev_data in the table of contents you will see that Appearance, Labeling, and Data tabs all appear. If you select either the World Topographic Map or World Hillshade only Appearance is added. If you select Map in the table of contents then all additional options are removed.
Along the bottom of the map view there are several tools available including:
Representative Fraction | Unit-less relation between map units and real-world units (e.g. 1 unit equals 30,000 units) |
Snapping | Moving a feature to match or coincide exactly with another point or feature’s coordinates when your pointer is within a specified distance or tolerance |
Constraints | Limits imposed on a model to maintain data integrity |
Grid | A network of parallel and perpendicular lines superimposed on a map and used for reference |
Inference | Analyzes the segment of the active sketch over which the pointer is hovering and displays inferred geometric constraints |
Corrections | Set grid corrections and offset |
X,Y Coordinates | X,Y location of the cursor; can be set to decimal degrees, degrees minutes seconds, degree decimal minutes, military grid reference system, national grid, or universal transverse mercator |
Selected Features | Depicts the number of items selected from a feature set |
Pausing Drawing | Stops the drawing of layers on the map view |
Refresh | Reloads the map view |
The mouse can be used to navigate around the map view. The left-click button is used to pan or move the map around the screen and view pop-ups, the scroll wheel is used to zoom or rotate/tilt (3D), and righ-click is used for continuous zoom by clicking and moving the cursor up to zoom out and down to zoom in.
On the Map tab there are a number of tools you should become familiar with as they will be useful throughout this course and beyond. Along with the Add Data button you have already used, the Fixed Zoom In/Out tools are used to adjust the level of zoom. The Full Extent tool is used to adjust the level of zoom to include the extent of all datasets. The Previous Extent tool is used to return the level of zoom to the previous level. There are a number of other tools you will use on this tab in future exercises. You should explore the different buttons on this tab to see what they do.
For this exercise you will familiarize yourself with another useful tool that allows you to examine information regarding the dataset. First, click on the ev_data layer in the table of contents. Next, click on the Explore button and move the cursor over the map. Your cursor will become a hand with pointed finger. If you click on the state of Tennessee a pop-up window will appear that provides data about the state.
You can scroll down on the data in the pop-up window and examine each attribute in the table. Along the bottom of the window you will see tools that can be used to: print the information for the selected feature , toggle selection on/off for the feature , flash the selected feature , and to zoom to the selected feature .
This method is helpful for getting information about a specific portion of the dataset. You can view all of the underlying information in the attribute table by right-clicking on the ev_data layer in the table of contents and clicking on Attribute Table.
Alternatively while the ev_data layer is selected in the table of contents you should see three new tabs highlighted in orange (color may vary) and titled Feature Layer. Under the Data tab you should see the Attribute Table tool.
Whichever method you used to open the attribute table you should now
have a new section on your screen that displays the attribute data for
all of the features in the dataset. In a future exercise you will learn
how to sort, query, and edit information within the attribute table. For
now, examine the numerous variables available for each state. What is
the column name and range of values for the electric vehicle charging
stations?
Hint: This information will be needed in the next
section.
Using the explore tool, what is the population of Tennessee in 2010 (POP2010)? What percentage of the population is female?Type your answers in a word document. The answers will need to be submitted at the conclusion of this lab.
Using the attribute table, find the area (SQMI ) of Colorado. How much larger is it than Wyoming?
The purpose of this exercise is to help familiarize you with the QGIS program. With this software, you will have the ability to view, create, and edit geographic data, query spatial data, examine spatial relationships, and create publishable maps. In these directions I will post images from both PC (on the left) and macOS (on the right) for each step. While your set-up may differ slightly, the configurations and layout of the tools should be similar.
When you begin a new exercise it would be beneficial to create a new folder specifically for the data and project files associated with the lab. This will help you to organize your data and be able to quickly refer back to it in later exercises. For this exercise you will need to download the Electric Vehicle Charging Station data from the GitHub Repository by clicking on the download button at this link and saving it in your exercise folder. Once the download is complete you will need to unzip the file by using double-click on macOS or right-click > extract all on PC.
To start the QGIS program press the Start Menu > QGIS or launch the application from the Mac Launchpad. It might be beneficial to create a shortcut on the desktop or add it to your dock for quicker access in the future. As the program loads, the opening screen will be extremely useful to you while working on future projects, however, for this exercise we will select New Empty Project.
The screen depicted below is separated into two sections. To the left there is the Browser and Layers sections, and on the right is the Map Canvas. Your version may vary slightly from the images. There are a number of ways to add data, but in this example we are going to use the browser window to connect to our project data folder.
In the Browser window on the left, navigate to the folder where you saved and unzipped the exercise data folder. Once you locate a folder in folder in the browser, you can use control+click (macOS) or right-click (PC) to Add as a favorite. This will link it to the favorites drop-down in the browser window giving you quicker future access. To add the data, you will navigate to the ev_data.shp file and then click-and-drag it to the map canvas. You will be able to add all types of data in this same way. If there is a pop-up window that mentions transformations go ahead and click OK. While the look of the US in this dataset is less than ideal, the purpose of this exercise is to ensure you know how to display data and basic tools for navigating the software. Transformations will be discussed further in a couple weeks after a lecture on projections and coordinate systems. For now, leave it with option 1 and click OK.
Your screen should now look similar to the screens below (colors may vary). Notice that the longitude and latitude values at the bottom of the screen adjust as you move your cursor.
You can now begin to explore some of the basic tools for navigating the map canvas such as:
|
|
|
|
|
|
|
Use these tools to zoom in and out, reposition the map on the
screen, and return to the current view using the zoom full
button.
Another useful tool is the identify features cursor which uses an icon with a lowercase i in a blue circle . This option extracts information for a selected feature from the attribute table of the selected layer.
If you wanted to view the entire underlying dataset you could
control-click (macOS) or right-click (PC) on the active layer and select
Open attribute table. In a future exercise you will
learn how to sort, query, and edit information within the attribute
table. For now, examine the numerous variables available for each state.
What is the column name and range of values for the electric vehicle
charging stations?
Hint: This information will be needed
in the next section.
Using the identify tool, what is the population of Tennessee in 2010? What percentage of the population is female?Type your answers in a word document. The answers will need to be submitted at the conclusion of this lab.
Using the attribute table, find the area (SQMI ) of Colorado. How much larger is it than Wyoming?
For each exercise in R you will need to load various packages that are used to complete analyses and graphical output. Generally these packages will be preloaded in the colab notebook however in subsequent labs you may need to install certain packages to complete the exercises. To install a package in R you use the following function where (“x”) is the name of a specific package.
install.packages("x")
Once the package has been installed, it will need to be loaded using a similar function:
library("x")
In the colab notebook for this exercise you will see where three
packages tidyverse, maps, and ggsn were installed and loaded.
Now that you have the packages required for the exercise you will need
to add the data. For this lab the data consists of state names,
abbreviations, and the number of electric vehicle recharing stations. To
avoid the need to download the data, you will the
read.csv()
function and a URL to import the data. Using the
head()
function will allow you to view the first few lines
of any dataset.
<- read.csv('https://raw.githubusercontent.com/chrismgentry/GIS1-Exercise-2/main/Data/ev_stations.csv')
evs head(evs)
In the script above you will see the use of <-.
This is an operator used to create an object that can be used in later
steps. If the script was written as
read.csv('https://raw.githubusercontent.com/chrismgentry/GIS1-Exercise-2/main/Data/ev_stations.csv')
the dataset would have been read and immediately displayed on the
screen. However, it would not have been available for subsequent
analyses. In colab, you can create your own code block and test it out
to see the results. Since you need this information for later, it is
important to use <- to create an object out of the
imported data. In this, and future exercises, you will see that operator
used frequently to create objects for analysis.
In order to create a map of electrical vehicle charging stations per
state you need to obtain information for the states and create a new
object. The tidyverse
package is a retainer for a number of
individual packages including the Grammar of Graphics or
ggplot2 package. This package will frequently be used to
display your data, but it also contains geographic information for the
US. You can obtain that information by using the map_data
function. In a new code block, you can use ?map_data
to
view help information on the function. Alternatively you can view the
documentation for any package or function by searching the package or
function name and cran (Comprehensive R Archive Network). For
this function you would search map_data cran
and the first
link is likely to be the RDocumentation
page for the function. Within this documentation you will find the
arguments available for the function and example scripts. So to create
an object that contains information for the continental US you can
use:
<- map_data('state') us
Using the Grammar of Graphics package, ggplot2
,
you can create a visualization of this data. Here is that script:
ggplot(us) +
geom_polygon(aes(x=long, y=lat, group=group), color = "white")
In this script you identified that you wanted to use
ggplot
to visualize the us object you
created in the previous step. Next ggplot
needs to know
what sort of object to draw. This is done by using the
geom_
function followed by a type of geometry. They include
point, line, polygon and other geometries such as histograms, boxplots,
violin plots for statistics, or contours, rasters, and tiles for three
dimensional data. So for this step you used geom_polygon
.
Next, ggplot
needs to know how the data should be
displayed. If you create a new code block and type str(us)
you can see the structure of the data and a few of the variables. You
will notice the dataset contains long (longitude), lat
(latitude), group, order, region (the state
names), and subregion. So in ggplot
you provide a
series of aesthetics using aes()
to direct
ggplot
on how to display the data. In this case,
x = long, y = lat
, and you need to tell it to organize the
groups by the category group. If you leave out group for this
specific script, ggplot
will be unsure what order to draw
the polygons and your map will not appear correctly.
color = "white"
tells ggplot
to use white
borders for the individual states. What do you think would happen if you
change the word color to
fill ? In the resulting image,
ggplot
used the information from your aesthetics to draw
the polygons and automate labels for the x and y axes. In a later step
you will learn how to customize those labels.
It may seem as if this is a difficult way to view the data. In other
software with a graphical user interface (GUI) you would most likely
click open, navigate to the folder containing the data, double-click on
that dataset, and then it would appear on your screen. Essentially,
every time you click “open” on a GUI interface, it is executing a
specific set of scripts to 1.) open the navigation window, 2.) allow the
selected file to be imported, and 3.) then display the information on
your screen. What you did above in three lines of code was to tell
ggplot
to 1.) create an object called us and 2.)
display it on the screen with some specific parameters. The benefit of
completing this in R versus something with a GUI
interface is, if you had three more similar datasets to view, you would
simply change US to another object and re-run the script. To
repeat the process in a GUI interface you would need to repeat all of
the steps from the beginning. This might not seem like much for three
steps, but what if your visualization had twenty steps, as many do? In
R you would still simply change the dataset and run the
same script, but in other programs you would need to repeat the same
twenty steps for each dataset. Additionally, if a colleague wanted to
display some data in the same way, you can either copy and paste the
code or type out each of the twenty steps with directions. Which of
these seems to be more consistently repeatable? Once you begin to
understand the syntax (order or arrangement of words and phrases to form
proper scripts) you will be more easily able to interpret sample scripts
and fix errors in your own code.
You used
ggplot(us) + geom_polygon(aes(x=long, y=lat, group=group), color = "white")
to create the visualization in this step. What script would you use to
make the same map but with black borders and blue
states? Add a code cell below this one, type the script, and run it to
view the output. Hint: color = “…..”, fill = “…..”
In this step you will organize and display the data in order to prepare it for the final visualization.
Now that you have the data displayed on the screen and understand how to access the underlying data, you need to customize the view so you can see the spatial distribution of electric vehicle charging stations in the US. As you may have guessed by now, there are a number of different ways to access the symbology tool needed to change how the data is displayed.
All three of these methods will show the symbology options in a panel on the right side of the screen. From here you will need to change the Primary Symbology from Single Symbol to Graduated Color. This can also be done by clicking on the drop-down menu for Symbology in the Apperance Tab.
After selecting Graduated Colors you will have several other options available in the symbology window. In order to sort by the number of electric vehicle charging stations per state you will need to change the Field category to ev_station. Next, in the Method category to Geometric Interval. Because of the range of values, choosing this option will help to balance out the bias of larger values. In the Classes category choose 5. Finally using the drop-down menu next to Color Scheme, select a color option for your visualization.
Depending on the color scheme you chose, your screen should now look similar to this:
On the left in the table of contents beneath the ev_data layer you will see the range of values represented by each color matching those values for each individual state on your map. At this point you should save your work. This can be done by going to the Project Tab > Save , using the CRTL+S keyboard shortcut, or using the quick save button to save your current project.
Question No. 2
In this step you used a
Graduated Colors symbology to visualize the data and organized
the values using a Geometric Interval method. There are
several other options within Method that could have been
selected as a display method such as:
Adjusting the Method value, describe how the visualization changes with each of these different options.Record your answers and submit at the conclusion of the lab.
Now that you have the data displayed on the screen and understand how to access the underlying data, you need to customize the view so you can see the spatial distribution of electric vehicle charging stations in the US. To begin you will need to control-click (macOS) or right-click (PC) on the ev_data in your layers and click on properties.
In the resulting window you will need to go to the Symbology tab (1.) in the left-hand menu. In this window you can change the fill of the polygons and change their opacity (or level of transparency). You can also adjust the symbology of your dataset. Those options are available in a selection bar at the top of the window. For this dataset they are:
|
|
|
|
|
|
|
|
|
|
|
|
|
For this specific data you will choose Graduated
(2.) since the data needs to be displayed by a range of numeric
values. Next you will select the ev_station variable
(3.) in the dataset. In the drop-down for the Color ramp
option you have a number of color options to choose. For this example
select Viridis (4.). Do you recall what the
range of values for the ev_station data? Because the
largest value is greater than 30,000 and the smallest value is around
100, you will need to set the Mode to a logarithmic
scale (5.) to properly display the data while avoiding a
bias of the larger values. Change the Classes to 6 (6.)
and click OK (7.).
Because the macOS and PC versions are identical only one image is shown.
Your screen should now look similar to this:
At this point you should save your work. Whether using macOS or PC, on the menu bar go to Project > Save As… and save your project in the folder you create for this exercise.
Question No. 2
In this step you used a
Graduated symbology to visualize the data and organized the
values logarithmically. There were several other options within
mode menu.
|
|
|
|
|
|
|
|
|
|
|
Adjusting the mode value, describe how the visualization changes with each of these different options.Record your answers and submit at the conclusion of the lab.
Now that you have datasets for electric vehicle charging stations
(object = evs) and the continental US (object =
us), you need to combined that data to allow for the
states to be color coded based on the number of charging stations per
state. To do this you will use a function called merge
from
the base R functions that will allow you to combine the
information from the evs and us into a
single dataset that contains information from both based on a common
variable. So to start you will need to determine what variable(s) are
contained within each dataset. You have seen how to examine datasets
using both head()
and str()
already in this
exercise. Create a new code block and examine the structure of each
dataset. You will see that there is a column for state name in each
except they are labeled differently. This is important information you
will need to properly merge
the datasets.
To do this you will first create an object (<-)
with a new name, then with the merge
function set the
following arguments:
So your final script will be:
<- merge(x = us, y = evs, by.x = "region", by.y = "state", all = TRUE)
states head(states)
Now you will see the columns for evs and abbreviation included in the us dataset. This new dataset will be what you use to visualize the information in the next step.
Question No. 2
Using summary(states)
in a new code cell, what are the
largest and smallest number of electric vehicle charging stations?
You will learn how to create a graphical display of your data that includes cartographic elements such as legend, scale bar, north arrow, etc.
Now it’s time to turn your data into a map. From the Insert Tab click on the New Layout button and choose a paper layout. For this exercise you should choose ANSI - Landscape, Letter 8.5” x 11”. This will open a new section where you will add the data, title, legend, north arrow, scale bar, and your name and date. If you have a large enough screen, you can right-click on the new layout and select Float. This will create a new window that you can resize while keeping the primary screen open. Otherwise, resize the layout section as necessary by moving your cursor between the two sections to adjust the border.
Whether viewing the new layout in a new window or section on the map page, click on the Insert tab and choose the Map Frame button. From there, select the map that has a representative fraction and has an image of the data from the map view.
When placed over the layout our cursor will become cross-hairs (+). Use it to draw the location of the map on the layout.
Your map will now be imported to the layout. To zoom in or out you can adjust the representative fraction at the bottom of the layout or on the Layout tab use the fixed zoom tools to change the level of zoom.
To adjust the location of the data, click the Activate button and use the Explore Button to click and drag and move the data on the map frame on the layout. When finished adjusting the view deactivate the layout by clicking the Close activated map frame button to return to the map layout. After you have adjusted the zoom and positioning your layout should look like this:
In order to complete a basic map you will need to add a north arrow , scale bar , legend , and text to include a title and the name and date of the map creator. Each of these items works essentially the same as adding the map data. When you click on each tool you can use your cursor to draw its location on the map. You will notice with the north arrow and scale bar there is a drop-down menu that allows you to select the specific style.
Each time you add an element such as a north arrow or scale bar, you will notice the section on the right will provide a number of different options to customize the element. Depending on the element you are adding there will be different buttons such as:
Options | Allows you to make elements visible or locked, change the title of the element, adjust the labels, or add columns | |
Display | Lets you adjust the border, background, or add a shadow to the element | |
Placement | Allows you to fine tune adjust the location of the element on the map and change the appearance and format of the text symbol of the element | |
Properties | This is specific to the scale bar and lets you adjust the number of divisions, numbers, marks, and bars of the element | |
Arrangement | Legend arrangement options allows you to adjust the fitting strategy, word wrap, and spacing of items within the element |
These will provide additional customization options for each element. When adding the Legend, notice that the information from the layer is added to the element. While you will examine how to customize all elements in future exercises, for this lab you will edit the names of the layer name and heading for the layer. This will update the information automatically in the legend. To begin, click once on the ev_data layer name in the table of contents. This will select the item. By single clicking an additional time (not double-clicking) it will allow you to directly edit the data.
Rename the layer Charging Stations and rename the ev_station heading to Number per State. Depending on placement and symbology color, your legend should now look like this:
Depending on where you placed your elements and customizations you employed, you should now have a completed map that includes all of the necessary elements discussed above.
Question No. 3
What is the largest and smallest number of electric vehicle charging stations?
Now it’s time to turn your data into a map. From the menu bar in either macOS or PC click Program > New Print Layout. This will open a new window where you will add the data, title, legend, north arrow, scale bar, and your name and date.
It will first ask you to create a print layout title. After you input a title clock OK.
In the new window you will see a blank layout page. If you control-click (macOS) or right-click (PC) on the page you will see options for Page Properties… that allows you to adjust the page size, orientation (landscape or portrait), or customize the width and height and provide a background color to the layout.There will also be an option to Manage Guides for Page… which will allow you to add or remove Horizontal or Vertical Guides that will help align items on the layout.
To add your data to the layout you will use the Add map tool that is located in the column of tools on the left side of the screen. When you select this tool and hover over the page layout your cursor will become a plus symbol. You will use this to draw a bounding box on the page layout that will serve as the location for the map data.
Once you have drawn the map box, the information displayed on the map canvas will be added to the print layout. Your screen should now look similar to this:
In order to complete a basic map you will now need to add a north arrow , scale bar , legend , and text to include a title and the name and date of the map creator. Each of these items works essentially the same as adding the map data. They can also be added through Add Item in the menu bar. There are several other buttons you should familiarize yourself with on the layout page such as:
Pan | The Pan Tool is used to shift the map canvas. This is useful when the canvas is larger than your display due to the level of zoom | |
Zoom | The Zoom Tool is used to increase the magnification of the map canvas, but is not used to zoom in on the data | |
Move Item Content | The Move Item Content Tool is used to move the map information within the bounding box and allows you zoom in and out on the map data | |
Select/Move Item | The Select/Move Item Tool is used to move items such as the north arrow on the map canvas | |
Lock/Unlock Items | Locking items keeps any changes from being made to the items on the layout | |
Group/Ungroup Items | These tools allow selected items to be grouped in order to remain together when moved | |
Raise/Align Items | These tools allow for items to be placed above or below another in their hierarchy or allows selected items to be aligned |
Once you choose the object you want to add, your cursor becomes a plus symbol and you are then able to draw the object in the desired location. Once you have placed each of the items, select any one, and in the control-click (macOS) or right-click (PC) menu choose Item Properties. This will open a new menu to the right of the screen that allows you to edit various properties like the symbol for the north arrow, scale bar units, legend item arrangement, and the text variables for the title, name and date.
Take your time to examine the various options within each of the properties menus. As you continue to make maps you will become more familiar with these menus and begin to develop your own style for each item. Hint: do not make the north arrow too large. At this point you should save the project.
Because the electric vehicle charging station data was organized logarithmically you can see that the values are displayed in scientific notation. Additionally, the display heading is the same as the name of the dataset. So to correct that you will return to the map canvas. If at any point you accidentally close the Print layout you can always open it again by clicking Show Layout Manager on the main toolbar. In the window select the layout you created and click Show.
Back in the layers area, control-click (macOS) or right-click (PC) on the ev_data layer and go to Properties and the Symbology tab on the left. from there you will see the options you selected earlier in the exercise. In the classes section, you will see three (3) columns of information: Symbol, Values, and Legend. The information in Legend can be edited by simply double-clicking on the text. Edit each legend entry to match the information in the values column. When you have completed click OK.
Finally, control-click or right-click on the dataset in layers and click Rename Layer. Give it a name that is representative of the dataset such as “Electric Vehicle Charging Stations”. Now return to your layout. If the information has not been updated, click the Refresh View button on the toolbar. Your layout should update with all of the changes you made in the Symbology Tab. You may also need to adjust the size of the legend now that you have edited the data. This is just one of a number of different ways to edit information for datasets. In future exercises you will examine other editing methods. You should now have a completed map that includes all of the necessary elements discussed above.
Question No. 3
What is the largest and smallest number of electric vehicle charging stations?
With this new dataset you are now ready to create a map to examine the distribution of electric vehicle charging stations across the country. In step one you used a very simple script to display the us data.
ggplot(us) +
geom_polygon(aes(x=long, y=lat, group=group), color = "white")
A similar script would allow you to quickly visualize the data
ggplot(states) + geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white")
,
however, you need to add a number of elements in order to create a map
such as a scale bar, north arrow, title, etc. Additionally, you can
customize other components to provide a better overall
visualization.
Earlier in the notebook we installed the ggsn
package.
This package allows you to add “north symbols and scale bars for maps
created with ‘ggplot2’ or ‘ggmap’.” So you can build on the script above
to create a map of the information in the states
dataset. To begin, run the script above with the added
fill argument to see the outcome:
ggplot(states) + geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white")
One thing you will notice is that the categories are very difficult
to distinguish. Because you have wide ranging data in the
evs_count column only the largest value is showing. A simple
fix to this would be to take the common logarithm of the data to
standardize the values by removing the skewness towards larger numbers.
The function scale-viridis
scales the data and provides a
color map designed to be perceived by viewers with common forms of color
blindness. So you can add
scale_fill_viridis_c(option = "D", trans = "log10")
to the
script above where:
The new script should now look like this:
ggplot(states) +
geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white") +
scale_fill_viridis_c(option = "D", trans = "log10")
Now that you are able to visualize the separations in the data you can add additional information. You can start with customizing the labels, map title, and legend title. This can all be completed by adding a single line of code containing all of the text information for those items:
ggplot(states) +
geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white") +
scale_fill_viridis_c(option = "D", trans = "log10") +
labs(x="Longitude",y="Latitude", title="Number of Electric Vehicle Charging Stations Per State", fill = "No. of Stations")
Feel free to edit the label names and the color option in the script
to provide your own customizations. Next you need to add a scale bar and
north arrow. To view the available options for the north arrow type
northSymbols()
into a new code block. The numeric values
below each symbol will be used in the script to identify the specific
style you choose. Because the north arrow, north
, is
specifically related to the map data you need to provide the following
arguments:
northSymbols()
So your new script will look like:
ggplot(states) +
geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white") +
scale_fill_viridis_c(option = "D", trans = "log10") +
labs(x="Longitude",y="Latitude", title="Number of Electric Vehicle Charging Stations Per State", fill = "No. of Stations") +
north(states, location = "bottomleft", scale = 0.05, symbol = 12, anchor = c(x= -70, y= 25))
In this example, location = "bottomleft"
means the
location of the north arrow will be based from the bottom left
of the symbol and ``anchor = c(x = -70, y = 25)``` is the geographic
location on the map to draw the symbol. For example, if the
anchors were set at -100 and 40 the symbol would be draw on the
Nebraska/Kansas border. Feel free to adjust the anchor points to draw
the north arrow in your preferred location.
Now you need to add a scale bar. Many of the arguments used for the
north arrow are duplicated for scalebar
ggplot(states) +
geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white") +
scale_fill_viridis_c(option = "D", trans = "log10") +
labs(x="Longitude",y="Latitude", title="Number of Electric Vehicle Charging Stations Per State", fill = "No. of Stations") +
north(states, location = "bottomleft", scale = 0.05, symbol = 12, anchor = c(x= -70, y= 25)) +
scalebar(states, dist = 250, dist_unit = "mi", transform = TRUE, model = "WGS84", location = "bottomleft", st.dist = 0.05, st.size = 2, anchor = c(x=-125,y=27))
As with all of the other customizations above, feel free to adjust the units, distance, text distance, and size based on your own style.
Finally, you will need to add text to the map to indicate the name of
the person who created the map and the date. In the future you will
possibly include references or other text based information. There are a
number of different ways you will explore for adding text information to
your maps, such as caption =
in labs, but for this example
you will use annotate()
. Similar to the north arrow and
scale bar, there will be a:
Your final script should now look similar to this:
ggplot(states) +
geom_polygon(aes(x=long, y=lat, group=group, fill = evs_count), color = "white") +
scale_fill_viridis_c(option = "D", trans = "log10") +
labs(x="Longitude",y="Latitude", title="Number of Electric Vehicle Charging Stations Per State", fill = "No. of Stations") +
north(states, location = "bottomleft", scale = 0.05, symbol = 12, anchor = c(x= -70, y= 25)) +
scalebar(states, dist = 250, dist_unit = "mi", transform = TRUE, model = "WGS84", location = "bottomleft", st.dist = 0.05, st.size = 2, anchor = c(x=-125,y=27)) +
annotate("text", x = -90, y = 25, label = "Chris Gentry\n August 2021", size = 2)
There is an exhaustive amount of modifications that can be applied to the map above, but for now you have the minimum information required to create a map of similar kinds of data. In future exercises you will use various function to customize the look of your maps.
Question No. 3
How does the dist = argument in the scalebar
function relate specifically to the distance of the scale bar on your
map? How would changing the value alter the appearance?
After a rash of severe weather over the past few years the Montgomery County Emergency Management Agency has asked you to provide a map detailing the number of reported tornadoes in each Tennessee county over the past several decades. This information will be shared with neighboring counties in middle Tennessee as a part of severe weather education campaign designed to inform communities about the risk of tornadoes in the region. The map should include all of the elements included on your previous map of electric vehicle charging stations such as:
Software specific directions can be found for each step below. Please submit the answer to the questions you answered above as well as your final tornado map by the due date.
This portion of the exercise is meant to reinforce the skills you learned in the first part of the lab. The steps to complete your final map will be to:
To begin this portion of the exercise you will need to download the tornado dataset. Remember you can use the pop-up tool or the attribute table to examine the information. When you have completed your map, click the Share Tab and click Layout to save your map.
You will have a new Export section on the right-side of the screen. In the Properties options change the File Type to *.jpg. This will allow you to add it to your word document and be submitted at the end of this exercise. In Name click the browse button to save the layout. It will default to the project folder and you can provide a name to identify the file. When done click Save in the browser window, leave the other options as the default setting, and Export at the bottom of the section.
Question No. 4Which county had the highest number of reported tornadoes?
Hint: Remember you can sort the data in any column by clicking on the column header.
This portion of the exercise is meant to reinforce the skills you learned in the first part of the lab. The steps to complete your final map will be to:
To begin this portion of the exercise you will need to download the tornado dataset. Remember you can use the identity tool or the attribute table to examine the information. When you have completed your map, click Project > Export as Image… on PC or Project > Import/Export > Export Map to Image… on macOS to save your map as a *.jpg. This will allow you to add it to your word document and be submitted at the end of this exercise.
Question No. 4
Which county had the highest number of reported tornadoes?
Hint: Remember you can sort the data in any column by clicking on the column header.
This portion of the exercise is meant to reinforce the skills you learned in the first part of the lab. The steps to complete your final map will be to:
merge
the
datasetsggplot
To begin this portion of the exercise you will need this URL to the comma delimited dataset:
https://raw.githubusercontent.com/chrismgentry/GIS1-Exercise-2/main/Data/tn_tornadoes.csv
This data represents the number of reported tornadoes in each county
from 1950-2020. As in step one of the exercise, you can use the
<- operator to create a new object and the
read.csv()
function with the link to the dataset to import
the data. Remember you can use head()
or str()
to examine the information.
To obtain county information for the State of Tennessee you should use the following script:
<- map_data('county', region = "tennessee")
tn head(tn)
If you search for map_data in the ggplot2 documentation you will find an example of a script used to isolate information for the State of Iowa that can be adapted for any state in the dataset. Remember when working with scripts, Google is your friend! All it requires is asking the correct question to find some example code online that can help guide you. There are numerous possible answers to the same problem so don’t hesitate to try other methods.
Using the example code from step two, you will need to
merge
the two datasets into a new object based on a common
variable such as Hint…hint county name.
Finally, by adapting the ggplot
code in step four, you
can map the information for tornado_count for each county in
Tennessee. In order to limit the scope of your map to just the state you
should add the following script to your modified ggplot
code from above:
coord_fixed(xlim = c(-90,-82), ylim = c(35, 37))
The coord_fixed()
function limits the axes based on
specified values. The values are based on the units of measure of the
data. In this can you see where the x axis is limited
(xlim) from -82° to -90° west longitude and the y
axis is limited (ylim) from 35° to 37° north latitude.
If you omit this script your map will likely have a “smashed”
appearance. For creating maps in R it is generally
advisable to set the x and y coordinates to ensure
proper display of your data. Remember you will need to adjust the anchor
points of your name and date text, north arrow and
scale bar to fit the current map view. Additionally, the
title and legend text should also reflect the
information depicted on your map.
Which county had the highest number of reported tornadoes?
Typesubset(tn_tornadoes, tornado_count == max(tornado_count))
into a new code cell or use Google to search for a county map of Tennessee to determine county locations on your map.
Hint: Replace tn_tornadoes in the code above with the object you created by merging the tornado and counties datasets.
The Montgomery County Emergency Management Agency has asked you to provide a map detailing the number of reported tornadoes in each Tennessee county over the past several decades. Based on the map you create above, complete a lab write-up that addresses the following questions:
When complete, send a link to your Colab Notebook or email the word document or PDF with answers to Questions 1-4 and your completed map.