![]() ![]() You can’t remove things without starting over. As with regular base plotting, you can think of creating maps like painting - every layer has to go on in the right order. ![]() ![]() The maps package provides easily accessible political boundary maps, that can be overlaid with other shapefiles. This style of map can be nicer for insets or large scale maps that would be cluttered with a raster background. If we don’t want any raster background to our maps, we can use base plotting and the maps package. Street map with HUC and gages Vector map example Compared to base plotting, it provides simplicity at the cost of control.Ĭolor = "black", fill = NA) + geom_sf(data = huc_gages_sf, inherit.aes = FALSE, color = "red") + geom_text(data = huc_gages_sf, aes(label = site_no, x = dec_long_va, y = dec_lat_va), Note that ggmap is probably not a good choice if you need your data to be in a particular projection. Many of the commands used here are from the ggplot2 package ( ggmap imports them), and others could be used to further customize this map. It creates the base map, which we can then add things to. The ggmap function is analogous to the ggplot function in the ggplot2 package that you have likely already used. st_bbox returns the bbox in the format we need, except for the names, which we add with setNames. For the location argument, we are getting the bbox from the huc_poly object. Since the basemaps that ggmap uses are quite detailed, they are too large to include with the package and must be retrieved from the web with the get_map function. Raster map exampleįor the raster map, we will use the ggmap package to create a road and satellite basemaps for the HUC. Now that we understand this new object, let’s make some maps. There are others, but we will use these three to get the parts of the sf object we need for plotting. st_geometry extracts the entire geometry part of the object st_bbox extracts the bounding box from the geometry and st_crs extracts the coordinate reference system. sf provides various functions to extract useful information from this kind object, generally prefixed with st_. Looking inside the object with the str command, we can see it is structured very much like a ame with several factor columns, except for the geometry column, which is of type sfc_POLYGON. The huc_poly object is a new type of object that we haven’t seen - it has classes sf as well as ame. # ts_id loc_web_ds medium_grp_cd parm_grp_cd srs_id access_cd Both dataRetrieval and sbtools are covered in our USGS Packages curriculum. Then we’ll retrieve gages with discharge from this watershed using the dataRetrieval package. We will be using sf throughout these examples to manipulate the points and polygon for the gages and HUC. The st_read function from the sf (for “simple features”) package reads in the shapefile. Setting upįirst, let’s download an example shapefile (a polygon) of a HUC8 from western Pennsylvania, using the sbtools package to access ScienceBase. In this post, we will show simple examples of raster and vector spatial data for plotting a watershed and gage locations, and link to some other more complex examples. Spatial data manipulation can be quite complex, but creating some basic plots can be done with just a few commands. Raster data can be thought of as pixels, similar to an image, while vector data consists of points, lines, or polygons. The main distinctions between them involve the types of data they work with - raster or vector - and the sophistication of the analyses they can do. There are many different R packages for dealing with spatial data. Reading Time 8 minutes Share Introduction ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |