How to save plot in pdf ? The active area (Viewport) has zero dimensions – ggplot2

Solution for How to save plot in pdf ? The active area (Viewport) has zero dimensions – ggplot2
is Given Below:

Hello everyone I’m using ggplot2 in order to save a plot into a pdf file, but I’m actually getting this error message :

Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto),  : 
  The active area (Viewport) has zero dimensions

here is the code I use:

library(ggplot2)
library(gggenes)
ggplot(data, aes(xmin = start, xmax = end, y = Scaff_name,fill=Category,forward=strand)) +
    facet_wrap(~ fct_reorder(Scaff_name,Scaffold_length_x), scales = "free", ncol = 1) +
    geom_gene_arrow()

Did someone already have this problem ?? Is there a way to sage a plot object without having to display it and get this issue ?


Here is the data if it can help to understand the issue:

    structure(list(start = c(13, 129, 1544, 10134, 15093, 24864, 
30052, 39812, 40302, 46039, 16560, 37234, 106, 18372, 29056, 
33275, 9, 1, 1586, 1622, 2772, 1696, 3671, 614, 2275, 2502, 1416, 
8, 1768, 16, 16341, 15077, 13863, 1452, 11970, 14239, 15, 1226, 
21319, 6983, 5086, 5528, 15015, 4988, 11559, 4685, 5835, 8680, 
1, 22733, 28366, 31093, 40848, 36122, 14317, 1953, 872, 868, 
450, 476, 4132, 1944, 17150, 20291, 25612, 12869, 3896, 5207, 
496, 498, 484, 16115, 18388, 14252, 8008, 9793, 6213, 4338, 1267, 
24089, 31532, 16332, 251, 4389, 8660, 286, 269, 1587, 4200, 11396, 
14261, 18737, 34603, 3748, 7049, 1593, 178, 16694, 6184, 3, 14318, 
1, 6193, 54, 77), end = c(408L, 402L, 3431L, 10929L, 16119L, 
26430L, 31093L, 40124L, 44454L, 47773L, 16899L, 41173L, 10886L, 
27749L, 30087L, 35010L, 363L, 375L, 4163L, 4199L, 3171L, 2457L, 
4007L, 2063L, 3046L, 3288L, 1641L, 367L, 2262L, 367L, 22514L, 
15527L, 14127L, 2795L, 12249L, 14428L, 291L, 1708L, 23191L, 9798L, 
5428L, 10243L, 15512L, 8483L, 14868L, 5678L, 6701L, 10615L, 1614L, 
24403L, 30018L, 34572L, 43025L, 36401L, 17461L, 2859L, 1198L, 
1195L, 914L, 812L, 5485L, 3504L, 17405L, 21254L, 26623L, 13825L, 
4232L, 7088L, 834L, 837L, 2070L, 17165L, 29112L, 14537L, 8836L, 
12850L, 7994L, 4974L, 1948L, 24638L, 32492L, 23083L, 1409L, 4914L, 
9452L, 619L, 661L, 1827L, 4553L, 11558L, 16424L, 20107L, 35217L, 
4314L, 7403L, 1782L, 346L, 17057L, 7216L, 513L, 15539L, 2071L, 
9460L, 482L, 461L), Scaff_name = c("scaffold_100890 -  C", "scaffold_100890 -  C", 
"scaffold_102 -  C", "scaffold_102 -  C", "scaffold_102 -  C", 
"scaffold_102 -  C", "scaffold_102 -  C", "scaffold_102 -  C", 
"scaffold_102 -  C", "scaffold_102 -  C", "scaffold_1087 -  A", 
"scaffold_1087 -  A", "scaffold_1087 -  A", "scaffold_1087 -  A", 
"scaffold_1087 -  A", "scaffold_1087 -  A", "scaffold_113654 -  C", 
"scaffold_113654 -  C", "scaffold_11995 -  C", "scaffold_12023 -  C", 
"scaffold_13532 -  A", "scaffold_13907 -  A", "scaffold_13907 -  A", 
"scaffold_17089 -  C", "scaffold_17089 -  C", "scaffold_17331 -  A", 
"scaffold_19321 -  C", "scaffold_20156 -  C", "scaffold_20156 -  C", 
"scaffold_20156 -  C", "scaffold_2133 -  A", "scaffold_2133 -  A", 
"scaffold_2232 -  A", "scaffold_2232 -  A", "scaffold_2456 -  A", 
"scaffold_2640 -  C", "scaffold_29090 -  A", "scaffold_29090 -  A", 
"scaffold_3015 -  A", "scaffold_3015 -  A", "scaffold_3035 -  A", 
"scaffold_3035 -  A", "scaffold_3035 -  A", "scaffold_3287 -  A", 
"scaffold_3287 -  A", "scaffold_3720 -  A", "scaffold_3720 -  A", 
"scaffold_3720 -  A", "scaffold_3720 -  A", "scaffold_3720 -  A", 
"scaffold_3720 -  A", "scaffold_3720 -  A", "scaffold_3720 -  A", 
"scaffold_3720 -  A", "scaffold_3720 -  A", "scaffold_3760 -  C", 
"scaffold_37691 -  C", "scaffold_37691 -  C", "scaffold_39976 -  A", 
"scaffold_39976 -  A", "scaffold_4174 -  C", "scaffold_4174 -  C", 
"scaffold_4174 -  C", "scaffold_4174 -  C", "scaffold_4174 -  C", 
"scaffold_4174 -  C", "scaffold_4286 -  A", "scaffold_4286 -  A", 
"scaffold_46093 -  C", "scaffold_46093 -  C", "scaffold_4982 -  A", 
"scaffold_4982 -  A", "scaffold_4982 -  A", "scaffold_4982 -  A", 
"scaffold_4982 -  A", "scaffold_4982 -  A", "scaffold_5348 -  C", 
"scaffold_5348 -  C", "scaffold_5447 -  C", "scaffold_596 -  A", 
"scaffold_596 -  A", "scaffold_596 -  A", "scaffold_596 -  A", 
"scaffold_596 -  A", "scaffold_596 -  A", "scaffold_61047 -  C", 
"scaffold_61047 -  C", "scaffold_6109 -  A", "scaffold_6109 -  A", 
"scaffold_617 -  A", "scaffold_617 -  A", "scaffold_617 -  A", 
"scaffold_617 -  A", "scaffold_6379 -  C", "scaffold_6379 -  C", 
"scaffold_7530 -  C", "scaffold_75374 -  C", "scaffold_7551 -  A", 
"scaffold_7613 -  C", "scaffold_77358 -  C", "scaffold_8350 -  A", 
"scaffold_8350 -  A", "scaffold_8350 -  A", "scaffold_84098 -  C", 
"scaffold_84098 -  C"), Category = c("Repeat element", "Felidae", 
"Ursidae", "Ursidae", "Ursidae", "Canidae", "Ursidae", 
"Ursidae", "Ursidae", "Ursidae", "Canidae", "Eukaryote gene", 
"Eukaryote gene", "Eukaryote gene", "Eukaryote gene", "Eukaryote gene", 
"Felidae", "Repeat element", "Griseidae", "Griseidae", 
"Hominidae", "Repeat element", "Felidae", "Unknown_EVE", 
"Unknown_EVE", "Hominidae", "Herpesviridae", "Repeat element", 
"Repeat element", "Felidae", "Eukaryote gene", "Unknown_EVE", 
"Canidae", "Eukaryote gene", "Canidae", "Felidae", 
"Felidae", "Repeat element", "Canidae", "Eukaryote gene", 
"Canidae", "Eukaryote gene", "Eukaryote gene", "Ursidae", 
"Eukaryote gene", "Eukaryote gene", "Eukaryote gene", "Eukaryote gene", 
"Eukaryote gene", "Eukaryote gene", "Eukaryote gene", "Eukaryote gene", 
"Eukaryote gene", "Canidae", "Eukaryote gene", "Rhabdoviridae", 
"Repeat element", "Felidae", "Repeat element", "Felidae", 
"Ursidae", "Ursidae", "Canidae", "Ursidae", "Ursidae", 
"Eukaryote gene", "Canidae", "Eukaryote gene", "Repeat element", 
"Felidae", "Eukaryote gene", "Eukaryote gene", "Eukaryote gene", 
"Canidae", "Eukaryote gene", "Eukaryote gene", "Repeat element", 
"Iridoviridae", "Unknown_EVE", "Ursidae", "Ursidae", "Eukaryote gene", 
"Ursidae", "Ursidae", "Canidae", "Felidae", 
"Repeat element", "Canidae", "Eukaryote gene", "Laridae", 
"Eukaryote gene", "Eukaryote gene", "Eukaryote gene", "Repeat element", 
"Felidae", "Felidae", "Felidae", "Canidae", 
"Rhabdoviridae", "Canidae", "Hominidae", "Eukaryote gene", 
"Eukaryote gene", "Repeat element", "Felidae"), strand = c(-1L, 
-1L, -1L, -1L, 1L, -1L, 1L, 1L, 1L, 1L, 1L, -1L, 1L, -1L, 
-1L, 1L, -1L, -1L, 1L, 1L, 1L, 1L, 1L, -1L, -1L, -1L, 1L, 
1L, -1L, 1L, -1L, 1L, -1L, 1L, -1L, -1L, -1L, -1L, 1L, -1L, 
-1L, 1L, 1L, -1L, -1L, 1L, -1L, 1L, -1L, -1L, 1L, -1L, -1L, 
1L, 1L, -1L, -1L, -1L, -1L, -1L, 1L, 1L, 1L, -1L, -1L, 1L, 
1L, -1L, -1L, -1L, 1L, 1L, -1L, 1L, -1L, -1L, 1L, 1L, 1L, -1L, 
-1L, 1L, -1L, -1L, -1L, 1L, 1L, -1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L), Scaffold_length_x = c(413, 
413, 50156, 50156, 50156, 50156, 50156, 50156, 50156, 50156, 
41560, 41560, 41560, 41560, 41560, 41560, 376, 376, 5123, 5439, 
7387, 4156, 4156, 3329, 3329, 5373, 2903, 3501, 3501, 3501, 32761, 
32761, 30445, 30445, 14704, 16355, 1708, 1708, 29114, 29114, 
19564, 19564, 19564, 15137, 15137, 43487, 43487, 43487, 43487, 
43487, 43487, 43487, 43487, 43487, 43487, 11559, 1198, 1198, 
1106, 1106, 29466, 29466, 29466, 29466, 29466, 29466, 19456, 
19456, 919, 919, 33464, 33464, 33464, 33464, 33464, 33464, 9305, 
9305, 9191, 36369, 36369, 36369, 36369, 36369, 36369, 662, 662, 
8463, 8463, 46036, 46036, 46036, 46036, 8190, 8190, 7635, 535, 
19568, 10064, 522, 16120, 16120, 16120, 484, 484)), row.names = c(NA, 
-105L), class = "data.frame")