sf

How to get ride of polygon borders using geom_sf in ggplot2

十年热恋 提交于 2020-02-03 05:23:04
问题 This question has been asked before in an old thread, but the accepted answer does not anymore in the current version of ggplot2. Here is a minimal example: library(ggplot2) library(rnaturalearth) world = ne_countries(scale = "medium", returnclass = "sf") ggplot(world) + geom_sf(aes(fill = pop_est)) + scale_fill_viridis_c(option = "plasma", trans = "sqrt") My question is: how can I get rid of the borders in each country? 回答1: Main Solution: color = NA In ggplot2 , borders of plotting objects

Distance between all the points to the first point

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 23:56:10
问题 I have points on a street, and Im trying to calculate the distance between all the points and the first point in the street Here is my sf object: library(rgeos) library(rgdal) library(sf) #I actually have multiple points on a segment of 5 Km df <- data.frame(lon = c(-121.95, -121.96, -121.97, -121.98), lat = c(37.35,37.36,37.37,37.38)) coordinates(df) <- c("lon", "lat") proj4string(df) <- CRS("+init=epsg:4326") df_sf <- st_as_sf(df) %>% st_transform(3488) I tried st_distance but the distance

Small multiple maps with geom_sf at the same spatial scale

允我心安 提交于 2020-01-24 10:46:05
问题 I would like to plot a figure with small multiple maps using ggplot2::geom_sf . The challenge here is how to do this keeping all maps centered in the image and at the same spatial scale. Here is the problem (data for reproducible example below): A simple map using facet_wrap put all polygons at the same spatial scale, but they are not centered. ggplot(states6) + geom_sf() + facet_wrap(~name_state) Here is a solution from this SO question that uses cowplot . In this case, polygons are centered

Fastest way to extract a raster in R (improve the time of my reproducible code)

蓝咒 提交于 2020-01-23 01:11:10
问题 I'm wondering if I have maximized the speed at which a mean of an area buffered around a point in a raster can be extracted. Can performance be improved any further on these LOCALLY? I use parallel mclapply already, and I know I could get further gains by setting up and running this on a cluster (use a cluster or get more cpu's is not the answer I'm looking for). Replicate some data: library(raster) library(parallel) library(truncnorm) library(gdalUtils) library(velox) library(sf) ras <-

R - crop LIST of Least Cost Paths intersected with SpatialPolygonsDataFrame objects

心已入冬 提交于 2020-01-16 08:13:06
问题 I have a series of steps I need to complete on a LIST of SpatialLinesDataFrame (=least cost paths flowing 'downslope' created using ] gdistance ; 'LCPs' herein) objects based on their relationships with individual features within a MULTI-FEATURE SpatialPolygonsDataFrame ('polygons') object. To summarize, each LCP element in the list originates inside a single polygon feature, and may or may not pass through one or more other polygon features as it 'flows' downhill. I want to create new

Size legend of sf object won't show correct symbols

旧巷老猫 提交于 2020-01-13 10:45:53
问题 Does anyone know why the legend of the size aestatic BIR74 won't show the dot sizes but rectangles? If the answer is yes, how can I fix this? Reproducable example: library(sf) # devtools::install_github("tidyverse/ggplot2") library(ggplot2) nc <- st_read(system.file("shape/nc.shp", package="sf")) nc_centers <- st_centroid(nc) nc_centers %>% ggplot() + geom_sf(aes(color = SID79, size = BIR74)) + coord_sf(datum = NA) + theme_minimal() 回答1: you need to add the show.legend argument to geom_sf, i

Size legend of sf object won't show correct symbols

﹥>﹥吖頭↗ 提交于 2020-01-13 10:45:10
问题 Does anyone know why the legend of the size aestatic BIR74 won't show the dot sizes but rectangles? If the answer is yes, how can I fix this? Reproducable example: library(sf) # devtools::install_github("tidyverse/ggplot2") library(ggplot2) nc <- st_read(system.file("shape/nc.shp", package="sf")) nc_centers <- st_centroid(nc) nc_centers %>% ggplot() + geom_sf(aes(color = SID79, size = BIR74)) + coord_sf(datum = NA) + theme_minimal() 回答1: you need to add the show.legend argument to geom_sf, i

Convert a list of sf objects into one sf

妖精的绣舞 提交于 2020-01-13 02:28:13
问题 I have a list of sf objects that I would like to row bind to create a single sf object. I'm looking for a function similar to data.table::rbindlist , that would stack the individual objects in an efficient manner. Data for reproducible example: my_list <- structure(list(structure(list(idhex = 4L, geometry = structure(list( structure(c(664106.970004623, 6524137.38910266), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT", "sfc"), precision = 0, bbox = structure(c(xmin = 664106.970004623

Replace geometries from a list in sf

折月煮酒 提交于 2020-01-04 05:28:17
问题 Suppose I have the following sf data frame: library(sf) nrows <- 10 geometry = st_sfc(lapply(1:nrows, function(x) st_geometrycollection())) df <- st_sf(id = 1:nrows, geometry = geometry) And I also have the following list: mylist = list('2'=st_point(c(-73,42)), '3'=NA) I want to replace the geometry from the second observation with the point in the list. I had thought about doing the following: st_geometry(df[names(mylist),]) <- st_sfc(mylist) But this throws an error: "Error in vapply(lst,

polygons from coordinates

旧城冷巷雨未停 提交于 2020-01-01 10:16:57
问题 I've got a data.frame with lat s and lng s that define the boundaries of rectangular boxes, like so geohash north_lat south_lat east_lng west_lng 1 gbsuv 48.69141 48.64746 -4.306641 -4.350586 2 gbsuy 48.69141 48.64746 -4.262695 -4.306641 What's the easiest way to convert this into an sf object that holds a column of POLYGON s? 回答1: The key to creating polygons is that the coordinates have to be in sequence to form a closed area (i.e., the last point is the same as the first point). So your