I have the following script to construct a ggmap, along with a polygon and some points. The example is not reproducible but this is not an issue because the problem that I face is related to the limits of the two axes. The code below:
ggMFI <- CY_map +
geom_point( data = coords_CY, aes(x = lon, y = lat), col = "black", size = 1.5 ) +
geom_sf(data = StudyArea_shp, colour = "white", inherit.aes = FALSE, show.legend = FALSE) +
geom_point( data = df_PREC, aes(x = lon, y = lat, col = dMFI), size = 2.5 ) +
#xlab("Longitude (°E)") + ylab("Latitude (°S)" ) +
scale_x_continuous(breaks = c(32.5, 33, 33.5, 34.0)) +
scale_y_continuous(breaks = c(34.6, 34.8, 35.0, 35.2)) +
theme(axis.text.x = element_text(size = 30),axis.text.y = element_text(size = 30) ) +
theme(axis.title.x = element_blank(),axis.title.y = element_blank() ) +
theme(legend.title=element_text(size=20),legend.text=element_text(size=20),
legend.position = c(0.94, 0.30)) +
scale_color_gradientn(colours = c('#5749a0', '#0f7ab0', '#00bbb1',
'#bef0b0', '#fdf4af', '#f9b64b',
'#ec840e', '#ca443d', '#a51a49'))
generates the following plot:
If I remove the scale_x_continuous, the map and the grey background coincide (no grey background can be seen)
but I do not have control on the axis scaling. How can I hide the grey background and make the map reaching the axes? PS: I have checked another relevant question in the stackoverflow, Expanding ggmap output and getting rid of grey but it does not answer exactly the same question that I have (the problem there is the presence of outlier points).
Including the line
+ coord_sf(expand = FALSE)
should fix your issue and still let you scale the axis as you prefer.