问题
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() +
geom_sf(aes(fill = AREA)) +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
回答1:
This issue was raised on the ggplot2 github site. You can remove the gridlines by either of:
Setting the colour of the gridlines to be transparent with
theme(panel.grid.major = element_line(colour = "transparent"))
Adding
coord_sf(datum = NA)
after callinggeom_sf
来源:https://stackoverflow.com/questions/49836184/cant-remove-gridlines-when-plotting-with-geom-sf