我对 ggplot2 中的图例几乎没有疑问。如何从所附代码中连续制作图例。在此代码中,图例采用离散形式,我想将其设为连续形式(平滑连续模式)。代码是可重现的(有点长,但可能在此代码中一行会发生变化)
library(sf)
library(sp)
r <- raster(t((volcano[,ncol(volcano):1] - 94) * 4.95))
# Let's mock with a shapefile
poly <- st_as_sfc(st_bbox(st_as_sf(rasterToPolygons(r))))
# Sample 4 points
set.seed(3456)
sample <- st_sample(poly, 4)
sample <- st_buffer(sample, c(0.01, 0.02, 0.03))
sample <- st_sf(x=1:4, sample)
st_write(sample, "1aa.shp", append = FALSE)
# Mocked data
# Now let's start with code -------
r <- raster(t((volcano[,ncol(volcano):1] - 94) * 4.95))
# Use sf!!
pg <- st_read("1aa.shp") # loadshapfile
plot(r)
plot(st_geometry(pg), add= TRUE,) # it appears here …Run Code Online (Sandbox Code Playgroud)