Skip to content
Prev 28532 / 29559 Next

merge ggplots into one with pipeline commands

Hi.

Thank you so much!
Excellent! It works wonderfully.
It will be very useful.

Should I abuse of your knowledge, take advantage of this example and ask if
you or anyone knows how to limit the map range to the area of the datasets
'dat', without saving xlim/ylim outside the plot?

i.e. making p1 automatically limited to the geographic range of dat, inside
the ggplot code (and not plotting always the complete country)?

like this, but automatically within the ggplot code (I have to make many
maps, each with different areas):

# this is what I would like to get:
ggplot(data = dat, aes(x=lon, y=lat)) +
    borders("world",fill="antiquewhite1",colour="antiquewhite4")+
  coord_fixed(ylim=c(min(dat$lat), max(dat$lat)),xlim=c(min(dat$lon) ,
max(dat$lon)))+
geom_point()

# however, with pipeline, I would need to set xlim and ylim outside the
plot code
ggplot(data = dat, aes(x=lon, y=lat)) +
    borders("world",fill="antiquewhite1",colour="antiquewhite4")+
  coord_fixed(ylim=c(min(.data[[lat]]), max(.data[[lat]])),xlim=c(min(.
data[[lon]]) , max(.data[[lon]])))+
geom_point()
#
https://stackoverflow.com/questions/4856849/looping-over-variables-in-ggplot

# this does not work either (if I use dat it refers to all dat, not only
when fac==1):
dat %>%
  filter(fac==1) %>%
  { p1 +
    geom_point(data=., aes(x=lon, y=lat))+
coord_fixed(ylim=c(min(data$y), max(data$y)),xlim=c(min(data$lon) , max(
data$lon)))+
geom_point()
  }
#
https://stackoverflow.com/questions/44889239/unable-to-pass-the-ylim-argument-to-ggplot-in-a-function

Thank you very much once again!
Best regards,
M.

Kent Johnson <kent3737 at gmail.com> escreveu no dia quinta, 4/02/2021 ?(s)
19:43: