I am attempting to remove the white borders around a facet plot that I created with geom_sf()
. Previously I was using the now deprecated rgdal
package and coord_cartesian()
. I am trying to get a similar graph plotted using geom_sf()
and coord_sf()
, but can't seem to get it to work.
My code:
land <- sf::read_sf("./shapefiles/Grey_WA_OR.shp")
land <- sf::st_transform(land, crs = "+proj=longlat +datum=WGS84")
water <- sf::read_sf("./shapefiles/NW_Marine.shp")
water <- sf::st_transform(water, crs = "+proj=longlat +datum=WGS84")
heatmap <- ggplot()+ theme_bw()+
geom_sf(data = water, fill = "paleturquoise3", color = "turquoise4") +
geom_sf(data = land, fill='grey96') +
coord_sf(xlim = c(-126.3, -122.3), ylim = c(48.3, 50.39)) +
geom_point(data= CPUE.bymonth.mean.nonzero, mapping = aes(x=Lon, y=Lat,
size=MeanCPUE), alpha = 0.5, colour= "coral", stroke = 0.7)+
geom_point(data = CPUE.bymonth.mean.zeros, mapping = aes(x = Lon, y = Lat,
size = MeanCPUE), alpha = 0.7, color = "gray25") +
scale_size_continuous(breaks = c(0, 500,1000, 3000), name = "Mean CPUE",
range = c(2.5,15)) +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())+
guides(size = guide_legend(override.aes = list(color =
c("gray25","coral","coral", "coral"), alpha = 0.6), size = 12))+
facet_grid(Year ~ Month)+
theme(
strip.text.x = element_text(size = 12, color = "black", face = "bold"),
strip.text.y = element_text(size = 12, color = "black", face = "bold"))
ggsave(filename = "figures/CPUE_map.png", plot = heatmap,
width = 12, height = 6, dpi = 600 )
What I get:
What I hope to get:
I've looked at the cowplot package but haven't been able to get that to work unfortunately, not sure if that package holds the solution? I've also tried removing the margins with theme(plot.margin = unit(c(0,0,0,0), "cm"))
, but no luck.