Skip to content
Prev 28533 / 29559 Next

merge ggplots into one with pipeline commands

Use ".", not ".data" and "lat" not "y" :

library(tidyverse)

p1 <- ggplot() +
   borders("world",
           fill = "antiquewhite1",
           colour = "antiquewhite4") +
   coord_fixed(ylim = c(36.6, 42.0),
               xlim = c(-10, -7)) +
   theme_minimal() +
   theme(panel.background = element_rect(fill = 'powderblue'),
         panel.grid.major = element_blank(),
         panel.grid.minor = element_blank()) +
   xlab("Longitude") +
   ylab("Latitude")
p1

dat <- data.frame(lat = c(40.3,38.4,39),
                   lon = c(-10,-8,-9),
                   fac = c(1,2,1))

dat %>%
   filter(fac == 1) %>%
   { p1 +
       geom_point(data = ., aes(x = .$lon, y = .$lat)) +
       coord_fixed(ylim = c(min(.$lat), max(.$lat)),
                   xlim = c(min(.$lon), max(.$lon))) +
       geom_point()
   }


Le 05/02/2021 03:33, > marta.m.rufino a ?crit?: