install.load::load_package("iemiscdata", "USA.state.boundaries", "data.table", "ggplot2",
"sf")
# load needed packages using the load_package function from the install.load
# package (it is assumed that you have already installed these packages)
# load the raddata_US_Fukushima_2011 data from iemiscdata {containing the US
# EPA Envirofacts RadNet (Radiation in the US)}
data(raddata_US_Fukushima_2011)
# load the state_boundaries_wgs84 data from USA.state.boundaries (for the US
# map)
data(state_boundaries_wgs84)
# remove the missing rows with location information missing
raddata_US_Fukushima_2011 <- raddata_US_Fukushima_2011[-which(is.na(raddata_US_Fukushima_2011$"Location 1 (Longitude)") |
is.na(raddata_US_Fukushima_2011$"Location 1 (Latitude)")), ]
## USA
USA <- state_boundaries_wgs84
# create the USA object with the same data as state_boundaries_wgs84
USA_projected <- st_transform(USA, "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23
+lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0")
# transform the coordinates to match those of the USA_state_boundaries_map data
# from USA.state.boundaries.data (formerly in USA.state.boundaries)
locations <- st_as_sf(raddata_US_Fukushima_2011, coords = c("Location 1 (Longitude)",
"Location 1 (Latitude)"), crs = "+proj=longlat +datum=WGS84 +ellps=WGS84")
# set the projection to longlat using sf
# due to an error message appearing in the tests-MKL, the following code has
# been added
if (any(st_is_valid(locations)) == FALSE) {
locations <- st_make_valid(locations)
}
# plot the map using ggplot2
p <- ggplot() + geom_sf(data = USA, colour = "black", fill = "white")
p <- p + geom_sf(data = locations, colour = "#3591d1", size = 0.5) + coord_sf(xlim = c(-60,
-170), ylim = c(0, 80), expand = FALSE)
# Source 1
p <- p + labs(x = "", y = "", title = "2011 Fukushima Radiation Sample Locations within the USA")
print(p)
How to map data with R: A hands-on tutorial to get you to start creating maps with R. By Abhinav Malasi, Jun 29, 2021. See https://medium.com/geekculture/how-to-map-data-with-r-8333110dff5b
EcoC²S Home – https://www.ecoccs.com/
About EcoC²S – https://www.ecoccs.com/about-ecoc2s.html
Services – https://www.ecoccs.com/services.html
1 Stop Shop – https://www.ecoccs.com/other-biz.html
Products – https://www.questionuniverse.com/products.html
Media – https://www.ecoccs.com/media.html
Resources – https://www.ecoccs.com/resources.html
R Trainings and Resources provided by EcoC²S (Irucka Embry, E.I.T.) – https://www.ecoccs.com/rtraining.html
All R code written by Irucka Embry is distributed under the GPL-3 (or later) license, see the GNU General Public License {GPL} page.
All written content originally created by Irucka Embry is copyrighted under the Creative Commons Attribution-ShareAlike 4.0 International license. All other written content retains the copyright of the original author(s).
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International license.