Bonsoir à tous,
Lorsque je sauvegarde en pdf avec ggsave un graphique ggplot l'image produite est carré. Si la zone de traçage est un rectangle, cela produit deux bandes supplémentaires par rapport à l'affichage dans RStudio/Rgui.
Je voudrais sauvegarder uniquement la zone de traçage avec le bon ratio.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  library(ggplot2)
  library(sf)
  x <- st_sfc(st_point(c(5, 5)))
  bbox <- st_bbox(x)
  xsize <- 10
  ysize <- 5
  bbox <- bbox + c(xsize / 2, ysize / 2,- xsize / 2, - ysize / 2)
  pol_sf <- st_sf(a = 1, geom =  st_as_sfc(bbox))
  gg <- ggplot() +
    geom_sf(data = pol_sf, fill = NA, color = "orange", size = 1, linetype = 1)
  gg <- gg + theme(
    panel.background = element_rect(fill = "grey"),
    plot.background = element_rect(fill = "blue")
  )
  plot(gg)
  pdf_file <- "issue_ggsave.pdf"
  ggsave(pdf_file)