I am using {ggplot}
and {marquee}
to render a plot. I tried to save the plot in .pdf
format but somehow the file I got is broken.
For example, this is what I get when I open it on a Windows machine using Adobe Reader:
[
I tried to:
- open the file on an Android device:
- render the plot in
.png
which works as I expected:
So, the question is: how do I render ggplot
+marquee
in .pdf
?
FYI this is my code:
range_max_dum <- 0.015
point_size <- 3
gray_line_size <- point_size - .75
max_color <- "#176b87"
min_color <- "#ffab40"
dum_legend <- glue::glue(
"Pooled effect sizes from {.[max_color] **all the included studies**} and {.[min_color] **when outliers and < median samle sizes removed**}",
.open = "[",
.close = "]")
dum_plot_data <-
tibble::tribble(
~country, ~es.x, ~ul.x, ~ll.x, ~es.y, ~ul.y, ~ll.y, ~min_es,
"China", 0.035799021, 0.044116242, 0.02832098, 0.023210599, 0.029256901, 0.017848775, 0.017848775,
"United Kingdom", 0.011771449, 0.032197434, 0.001366486, 0.004588374, 0.008391918, 0.001920112, 0.001366486,
"United Arab Emirates", 0.010544074, 0.013057569, 0.008294895, 0.010544074, 0.013057569, 0.008294895, 0.008294895,
"India", 0.050080298, 0.07488636, 0.030041038, 0.019575116, 0.037859183, 0.007191735, 0.007191735,
"Saudi Arabia", 0.003460838, 0.004283512, 0.002725023, 0.003460838, 0.004283512, 0.002725023, 0.002725023,
"Canada", 0.024949252, 0.038100772, 0.01451395, 0.011457303, 0.01343168, 0.009637608, 0.009637608
)
dum_plot_data %>%
ggplot(aes(y = country)) +
geom_linerange(
aes(xmin = es.y, xmax = es.x),
color = "gray65",
linewidth = gray_line_size,
alpha = .32) +
geom_linerange(
xmin = -.05,
aes(xmax = min_es),
color = "gray10",
linetype = 5,
linewidth = .35,
alpha = .45) +
geom_point(
aes(x = es.y),
color = min_color,
size = point_size) +
geom_linerange(
aes(xmin = ll.y, xmax = ul.y),
color = min_color,
alpha = .5) +
geom_point(
aes(x = es.x),
color = max_color,
size = point_size) +
geom_linerange(
aes(xmin = ll.x, xmax = ul.x),
color = max_color,
alpha = .5) +
scale_x_continuous(
limits = c(0, range_max_dum), labels = scales::label_percent(),
breaks = seq(0, range_max_dum, by = .05)) +
labs(
x = "Incidence",
title = dum_legend) +
theme_minimal() +
theme(
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank(),
axis.title.y = element_blank(),
axis.title.x = element_text(face = "bold", size = 12.5),
axis.text.x = element_text(hjust = 1, size = 10),
plot.title = element_marquee(width = 1))
ggsave(
filename = "test.pdf",
device = "pdf",
width = 20,
height = 30,
units = "cm")
Session Info:
sessionInfo()
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
time zone: Asia/Tehran
tzcode source: internal
attached base packages:
[1] stats graphics grDevices
[4] utils datasets methods
[7] base
other attached packages:
[1] marquee_0.1.0
[2] ggtext_0.1.2
[3] glue_1.7.0
[4] ggforce_0.5.0
[5] showtext_0.9-6
[6] showtextdb_3.0
[7] sysfonts_0.8.8
[8] sf_1.0-16
[9] rnaturalearthhires_1.0.0.9000
[10] rnaturalearthdata_1.0.0
[11] rnaturalearth_1.0.1
[12] furrr_0.3.1.9000
[13] future_1.34.0
[14] magick_2.8.3
[15] officer_0.6.7
[16] flextable_0.9.7
[17] broom_1.0.6
[18] metafor_4.6-0
[19] numDeriv_2016.8-1.1
[20] metadat_1.2-0
[21] Matrix_1.6-5
[22] janitor_2.2.0
[23] lubridate_1.9.3
[24] forcats_1.0.0
[25] stringr_1.5.1
[26] dplyr_1.1.4
[27] purrr_1.0.2
[28] readr_2.1.5
[29] tidyr_1.3.1
[30] tibble_3.2.1
[31] ggplot2_3.5.1
[32] tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] DBI_1.2.1
[2] readxl_1.4.3
[3] rlang_1.1.4
[4] magrittr_2.0.3
[5] snakecase_0.11.1
[6] e1071_1.7-14
[7] compiler_4.3.3
[8] systemfonts_1.1.0
[9] vctrs_0.6.5
[10] pkgconfig_2.0.3
[11] crayon_1.5.3
[12] fastmap_1.2.0
[13] backports_1.4.1
[14] labeling_0.4.3
[15] utf8_1.2.4
[16] rmarkdown_2.29
[17] tzdb_0.4.0
[18] camcorder_0.1.0
[19] ragg_1.3.3
[20] xfun_0.49
[21] jsonlite_1.8.9
[22] tweenr_2.0.2
[23] uuid_1.2-1
[24] terra_1.7-71
[25] parallel_4.3.3
[26] R6_2.5.1
[27] stringi_1.8.3
[28] parallelly_1.39.0
[29] car_3.1-2
[30] cellranger_1.1.0
[31] Rcpp_1.0.13-1
[32] knitr_1.49
[33] timechange_0.3.0
[34] tidyselect_1.2.1
[35] rstudioapi_0.16.0
[36] abind_1.4-8
[37] codetools_0.2-19
[38] listenv_0.9.1
[39] lattice_0.22-5
[40] withr_3.0.2
[41] askpass_1.2.1
[42] evaluate_1.0.1
[43] units_0.8-5
[44] proxy_0.4-27
[45] polyclip_1.10-6
[46] zip_2.3.1
[47] xml2_1.3.6
[48] pillar_1.9.0
[49] carData_3.0-5
[50] KernSmooth_2.23-22
[51] generics_0.1.3
[52] rprojroot_2.0.4
[53] mathjaxr_1.6-0
[54] hms_1.1.3
[55] munsell_0.5.1
[56] scales_1.3.0
[57] globals_0.16.3
[58] class_7.3-22
[59] gdtools_0.4.1
[60] tools_4.3.3
[61] data.table_1.16.2
[62] grid_4.3.3
[63] colorspace_2.1-1
[64] nlme_3.1-164
[65] cli_3.6.3
[66] textshaping_0.4.0
[67] rsvg_2.6.0
[68] fontBitstreamVera_0.1.1
[69] fansi_1.0.6
[70] svglite_2.1.3
[71] gtable_0.3.6
[72] rstatix_0.7.2
[73] digest_0.6.36
[74] fontquiver_0.2.1
[75] classInt_0.4-10
[76] gifski_1.12.0-2
[77] farver_2.1.2
[78] htmltools_0.5.8.1
[79] lifecycle_1.0.4
[80] here_1.0.1
[81] httr_1.4.7
[82] gridtext_0.1.5
[83] fontLiberation_0.1.0
[84] openssl_2.2.2
[85] MASS_7.3-60.0.1
5