2
I have these dice:
structure(list(lon = c(-84.375, -84.125, -83.875, -83.625, -83.375,
-83.125, -82.875, -82.625, -82.375, -82.125, -81.875, -81.625,
-81.375, -81.125, -80.875, -80.625, -80.375, -80.125, -79.875,
-79.625, -79.375, -79.125, -78.875, -78.625, -78.375, -78.125,
-77.875, -77.625, -77.375, -77.125), lat = c(-52.625, -52.625,
-52.625, -52.625, -52.625, -52.625, -52.625, -52.625, -52.625,
-52.625, -52.625, -52.625, -52.625, -52.625, -52.625, -52.625,
-52.625, -52.625, -52.625, -52.625, -52.625, -52.625, -52.625,
-52.625, -52.625, -52.625, -52.625, -52.625, -52.625, -52.625
), pr = c(743.868774414062, 745.477661132812, 740.24267578125,
737.242797851562, 734.242919921875, 731.242980957031, 800.98876953125,
803.612670898438, 806.236572265625, 808.860473632812, 712.187622070312,
710.083129882812, 710.976013183594, 712.867919921875, 919.867614746094,
918.26416015625, 916.660705566406, 915.677490234375, 945.941589355469,
946.579406738281, 947.217224121094, 947.855041503906, 1108.41198730469,
1108.90100097656, 1112.51672363281, 1116.13244628906, 1070.11169433594,
1069.80126953125, 1069.49096679688, 1074.63659667969)), row.names = c(NA,
30L), class = "data.frame")
I’m using the code below, however the caption for the countries and basin Shape does not appear if you leave the caption for the raster file. Follows the code:
library("ggplot2")
library("rnaturalearth")
library("RColorBrewer")
world <- ne_countries(scale = "medium", returnclass = "sf")
ggplot() +
geom_raster(data = datapr, aes(x = lon, y = lat, fill = pr)) +
scale_fill_gradientn("kg m-2 s-1", colours = rev(brewer.pal(10, "RdBu"))) +
geom_sf(data = st_as_sf(world), aes(fill = "Países"),show.legend = "polygon",
colour = "red", alpha = 0) +
geom_sf(data = st_as_sf(sfshape),aes(fill = "Bacia"),
colour = "blue",alpha = 0, show.legend = "polygon")
I would like to know how to adjust the code, specifically in the function geom_sf to appear its legend, whether polygon, line or point and keep the legend of geom_raster.
How to reproduce the other data besides
world
– Tomás Barcellos
@Tomásbarcellos the data is in a link in the question in a file . Rdata
– Artur_Indio
This is not the "good practice" here at Sopt. It includes the result of
dput(head(minha_base, 30))
for each of the data that is used in the question (except those that comes from the package with theworld
)– Tomás Barcellos
Another thing, the answer does not solve? Even with the limitation of the data?
– Tomás Barcellos
@Tomásbarcellos does not solve. See that in addition to putting the caption for geom_sf, I need it for the two world and sfshape files (I can not generate the dput of the last), I still need a caption for geom_raster (I put now question)
– Artur_Indio