sf

Removing the Great Lakes from US county-level maps in R

二次信任 提交于 2019-12-31 02:25:15
问题 I am using R to draw US map at county level. I downloaded the shapefile for US from GADM. The county-level shape file is "gadm36_USA_2.shp". I then used the code below to draw map: library(sf) library(tidyverse) us2 <- st_read("<Path>\\gadm36_USA_2.shp") mainland2 <- ggplot(data = us2) + geom_sf(aes(fill = NAME_2), size = 0.4, color = "black") + coord_sf(crs = st_crs(2163), xlim = c(-2500000, 2500000), ylim = c(-2300000, 730000)) + guides(fill = F) The Great Lakes region (shown by red arrows)

Can't remove gridlines when plotting with geom_sf

元气小坏坏 提交于 2019-12-30 08:07:10
问题 The standard means of removing gridlines seem futile when plotting with geom_sf . For instance, if we plot a simple ggplot object, this works to remove the grid library(tidyverse) library(sf) mtcars %>% ggplot( aes(disp, hp) ) + geom_point() + theme( panel.grid.major = element_blank(), panel.grid.minor = element_blank() ) returns but the same code fails to remove the grid when you plot using geom_sf "shape/nc.shp" %>% system.file( package = "sf" ) %>% st_read( quiet = TRUE ) %>% ggplot() +

Create Multilines from Points, grouped by ID with sf package

社会主义新天地 提交于 2019-12-30 07:15:24
问题 I have a collection of Points, with a LINEID and an ID_SEQ . The LINEID determines the unique Line-IDS, while the ID_SEQ determines the order of the points in a Line-ID. I want to transform Points to Lines, ordered by ID_SEQ and grouped by LINEID . With the package sp , I am able to achieve the desired results, but I want to do it with the sf package. What am I missing here? Here is some dummy data, the desired result illustrated with sp -functions and two attempts to do the same with sf ,

Create Multilines from Points, grouped by ID with sf package

橙三吉。 提交于 2019-12-30 07:14:10
问题 I have a collection of Points, with a LINEID and an ID_SEQ . The LINEID determines the unique Line-IDS, while the ID_SEQ determines the order of the points in a Line-ID. I want to transform Points to Lines, ordered by ID_SEQ and grouped by LINEID . With the package sp , I am able to achieve the desired results, but I want to do it with the sf package. What am I missing here? Here is some dummy data, the desired result illustrated with sp -functions and two attempts to do the same with sf ,

Plotting points and multipolygon objects in R with sf

不问归期 提交于 2019-12-25 03:08:03
问题 I've been trying to plot both points and multipolygon sf objects with no success. Following is a reproducible example of my problem. library(sf) library(magrittr) library(RColorBrewer) nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(crs = 4326) points <- data.frame(p = seq(15, 75, 15), long = c(-85, -80, -78, -75, -82), lat = c(34, 36, 37, 38, 35)) %>% st_as_sf(coords = c('long', 'lat'), crs = 4326) points$p_cut <- cut(points$p, seq(0, 100, 20)) #plot1 plot(points[

error when clipping sf voronoi polygons to boundary box

人盡茶涼 提交于 2019-12-24 03:41:14
问题 I am trying to 'clip' voronoi-polygons (created with the sf-package) to a boundary box... But it throws me an error that I cannot define. I'm not very experienced in the spatial-worldof R. All help is appreciated. sample data stations <- structure(list(STN = c(209L, 210L, 215L, 225L, 235L, 240L, 242L, 248L, 249L, 251L, 257L, 258L, 260L, 267L, 269L, 270L, 273L, 275L, 277L, 278L, 279L, 280L, 283L, 285L, 286L, 290L, 308L, 310L, 311L, 312L, 313L, 315L, 316L, 319L, 323L, 324L, 330L, 331L, 340L,

Insert geom_sf layer underneath existing geom_sf layers

南笙酒味 提交于 2019-12-24 01:27:08
问题 I have a basic map of India with states and borders, some labels, and a number of other specifications stored as a gg object. I'd like to generate a number of maps with a district layer, which will bear data from different variables. To prevent the district maps overwriting state and country borders, it must be before all the previous code, which I'd like to avoid repeating. I thought I could do this by calling on $layers for the gg object as per this answer. However, it throws an error.

Projection differences in R using sf and sp

余生颓废 提交于 2019-12-23 22:22:29
问题 I have a grid I have converted from GeoTIFFs to a shapefile. I would like to convert and export the shapefile as a GeoPackage and change the projection so it uses the British National Grid as the geographic coordinate system when opened in a GIS. However this only seems to work using sp and not sf (which does not appear to retain aspects like the datum). This is a problem as I would like to export GeoPackages containing multiple layers which you can only currently do in sf and not sp . Am I

R: Unusual error plotting multipolygons with ggplot, geom_sf, and openstreetmap

自古美人都是妖i 提交于 2019-12-23 22:01:28
问题 I am trying to plot Lake Geneva/Lac Leman using {ggplot2}, {osmdata} and {sf}. I am getting an error whenever I try to plot the lake multipolygons (of which there are 5). I can't find any mention of this error elsewhere. library(osmdata) #> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright library(tidyverse) lake_gva <- getbb("Geneva") %>% opq()%>% add_osm_feature(key = "natural", value = "water") %>% osmdata_sf() lake_gva #> Object of class 'osmdata' with:

geom_sf size argument doesn't work when size < 1

て烟熏妆下的殇ゞ 提交于 2019-12-23 09:58:00
问题 Question: I'm trying to create a map of U.S. states/counties with the sf package and geom_sf() from ggplot2, but I can't get the size argument for polygon border line width in geom_sf() to properly create thin lines when size < 1 (e.g. ggplot(sf_obj) %>% geom_sf(size = 0.5) . Specifically, the border lines of a state/county appear to have the same width from the arbitrarily small (e.g. size = 0.05 ) all the way up to size = 0.702 . Then there seems to be a strange cutoff at size = 0.702 ,