I have a question about facet_wrap() in ggplot2. I am trying to make a graph that looks like this. I attach an example image 1.enter image description here
In image 1 it can be seen that there are two maps and each one has its legend and color scale. I would like to be able to do this with ggplot and the facet_wrap() function.
My problem is that because the data in the dataframe is very different, they have a lot of amplitude for each map, when plotting the scale it does not allow me to visualize it the way I want.
ggplot(dataframe,mapping=aes(x=lon,x=lat))
geom_contour_fill((aes(z=hgt,fill=stat(level)))
geom_contour(aes(z=hgt),color="black",size=0.2)
scale_fill_distiller(palette = "YlOrBr",direction = 1,super=ScaleDiscretised)
mi_mapa
coord_quickmap(xlim = range(dataframe$lon),ylim=range(dataframe$lat),expand = FALSE)
facet_wrap(~nombre_nivel,scales="free", ncol =2)
labs(x="Longitud",y="Latitud",fill="altura",title = "campos")
my dataframe has a shape like this. Where the facets are determined by the level variable. In this case the dataframe has another variable which is temp instead of hgt, but it's just another name.
Thanks
CodePudding user response:
I think I've faced the alike problem building the two parts of the single map with two different scales. I found the package grid
useful.
library(grid)
grid.newpage()
print(myggplot, vp = specifiedviewport)
In my case I built the first p <- ggplot()
than adjusted p2 <- p ...
with printing the two ggplots (p
and p2
) in two viewports. You can newly construct p2
with individual scale and print it in the grid. You can find useful information
here.