I have a sf dataframe called polyg_sf that I'd like to plot with geom_sf. On every line there is the test value at location and the layer corresponds to identical locations (a square on my map at resolution 0.05). Here's how the head of the dataframe is looking :
layer Month test geometry
75 01 5.92 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 02 4.37 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 03 5.63 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 04 8.13 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 05 6.86 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 06 9.46 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 07 10.5 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 08 19.7 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 09 12.9 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
75 10 10.4 POLYGON ((-2.025 43.625, -1.975 43.625, -1.975 43.675, -2.025 43.675, -2.025 43.625))
There are 44136 observations in the dataframe with multiple layer numbers.
I want to plot this data using geom_sf.
Here is how I do it :
pred_plot <- ggplot(polyg_sf) +
geom_sf(aes(col = test)) +
coord_sf(xlim = c(-6,0), ylim = c(43,48), expand = FALSE)+
scale_color_distiller(palette = "Spectral") +
labs(caption= "k = 0.75")+
xlab("Longitude (deg)")+
ylab("Latitude (deg)")+
guides(col=guide_colorbar(ticks.colour = NA))+
facet_wrap(. ~ Month)
This is the plot I get with this command :
As you can see, the plot is checkered, leaving some empty spots where there is no data. I would like something where every pixels are next to each other. Do you happen to know how to solve this issue ?
Is it related to my grid set up ?
Thanks !
Edit : Thanks to margusl, I was able to fill in the polygons.
Here is the updated code :
pred_plot <- ggplot(polyg_sf) +
geom_sf(aes(fill = test, col=test)) +
coord_sf(xlim = c(-6,0), ylim = c(43,48), expand = FALSE)+
scale_color_distiller(palette = "Spectral") +
scale_fill_distiller(palette = "Spectral")+
labs(caption= "k = 0.75")+
xlab("Longitude (deg)")+
ylab("Latitude (deg)")+
guides(col=guide_colorbar(ticks.colour = NA))+
facet_wrap(. ~ Month)
I now get this plot
But there are regular lines that don't seem to fit to my data. Any tips on why is that ?