Class 14
districts <- st_read(system.file("extdata/districts.geojson",
package = "geospaar"))
farmers_sf <- read_csv(system.file("extdata/farmer_spatial.csv",
package = "geospaar"))
farmers_s <- st_as_sf(farmers, coords = c("x", "y")) %>%
st_set_crs(st_crs(districts))
roads <- st_read(system.file("extdata/roads.geojson", package = "geospaar")) %>%
st_transform(x = roads, crs = st_crs(districts))
pt <- st_point(x = c(28, -14))
pts <- st_multipoint(x = cbind(x = c(27.5, 28, 28.5), y = c(-14.5, -15, -15.5)))
sline <- st_linestring(cbind(x = c(27, 27.5, 28), y = c(-15, -15.5, -16)))
pol <- st_polygon(list(cbind(x = c(26.5, 27.5, 27, 26, 26.5),
y = c(-15.5, -16.5, -17, -16, -15.5))))geom_sf()st_area(), st_length. Default units are in metersgeom_sf() to plot areascale_fill_continuous , with type = 'viridis'districts <- districts %>%
mutate(areadiff = (area - area2) / area * 100)
ggplot(districts) +
geom_point(aes(x = area2, y = areadiff))
districts %>%
mutate(areadiff = ((area - area2) / area) * 100) %>%
ggplot() + geom_point(aes(x = area2, y = areadiff))
districts %>%
mutate(areadiff = ((area - area2) / area) * 100) %>%
summarize(mu = mean(areadiff))districts %>%
mutate(areadiff = ((area - area2) / area) * 100) %>%
ggplot() + geom_sf(aes(fill = areadiff))
districts %>%
mutate(areadiff = ((area - area2) / area) * 100) %>%
summarize(mu = mean(areadiff)) %>%
ggplot() + geom_sf(aes(fill = mu))
districts %>%
mutate(areadiff = ((area - area2) / area) * 100) %>%
st_drop_geometry() %>%
summarize(mu = mean(areadiff)) #%>%
# ggplot() + geom_sf(aes(fill = mu))
districts %>%
mutate(areadiff = ((area - area2) / area) * 100) %>%
as_tibble() %>%
summarize(mu = mean(areadiff)) #%>%st_length() to add column ‘road_length’ to roadsscale_color_continuous() )lwd = 1)theme_bw()roads <- st_read(
system.file("extdata/roads.geojson", package = "geospaar")
)
roads <- roads %>%
mutate(road_length = as.numeric(units::set_units(st_length(.), "km")))
ggplot() +
geom_sf(data = districts, color = "black", fill = NA) +
geom_sf(data = roads, aes(color = road_length), lwd = 1) +
scale_color_viridis_c() +
theme_minimal()ggplot(). You can include data if you’re only using one data set.geom_point, geom_line, geom_sf, geom_histogram)aes(). These are columns used for plotting.geom_point, geom_line you need ‘x’ and ‘y’ aesthetics.geom_sf, spatial context used for ‘x’ and ‘y’. But you might want ‘fill’ or ‘color’