We'll start by loading the necessary packages.
library("sf") library("dplyr") library("tmap") library("jrSpatial")
loc = data.frame(lon = , lat = ). You can use Google Maps to find our current longitude and latitude.loc = data.frame(lon = -1.6053, lat = 54.9705)
st_sf(). Because our coordinates are just numeric columns instead of a single geometry column, we can't use st_sf(). Instead we have to use st_as_sf() and specify the coordinate columns using the coords argument, like so loc = st_as_sf(loc, coords = c("lon", "lat"))
st_is_longlat() to check whether the data is recognised as using longlat degrees. What about st_crs()?st_is_longlat(loc) st_crs(loc) # no longlat because we have not set the coordinate ref system yet
st_set_crs() and then check st_is_longlat() again. loc = st_set_crs(loc, 4236) st_is_longlat(loc)
Question 2.
data(nz_missing, package = "jrSpatial"). Plot the data using tm_shape() with tm_borders(). What do you notice?data(nz_missing, package = "jrSpatial") tm_shape(nz_missing) + tm_borders() + tm_fill() # Part of New Zealand is missing.
data(canterbury, package = "jrSpatial")
Say we have two spatial data frame, x and y, we can row bind them by using
rbind(x, y)
Try to use rbind() to add the Canterbury row to the original New Zealand data. What does the output tell you?
nz = rbind(nz, canterbury) # The two data sets have different CRS. R won't let us combine them.
st_crs(). Then use st_transform() to transform the Canterbury data to use the same CRS as the rest of New Zealand. Combine the data with rbind() and plot the output. st_crs(nz_missing) canterbury = st_transform(canterbury, 4326) nz = rbind(nz_missing, canterbury) tm_shape(nz) + tm_borders() + tm_fill()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.