Plots crash while exporting as .svg

svg

#1

Greetings! RStudio plots crash and I lose all of the generated plots when I try to save it as .svg. The .svg plot doesn't get generated either. I am using RStudio Version 1.1.456 on macOS High Sierra Version 10.13.6 (4.2GHz Intel Core i7 processor, 32GB memory). Kindly help as I need the plots in .svg format.
Many thanks!
Best regards,
Amruta


#2

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.


#3


#4

Hi,

After you run reprex, the code and output will be on your clipboard (or in a markdown file, if you chose to run it as such). Can you please paste the output here as opposed to a screenshot? That way others can try to help you troubleshoot without having to read and type from a picture.

Thanks

n.b. you don't need to reinstall the packages inside of the reprex!


#5

Thanks Mara - I actually tried to post the .md files, the .r script as well as the html but that did not work. I am not allowed to upload the files as i am a new user.
Amruta


#6
install.packages(c("tidyverse","reprex","ggplot2"))
#> Installing packages into '/Users/arphatak/Library/R/3.5/library'
#> (as 'lib' is unspecified)
#> 
#> The downloaded binary packages are in
#>  /var/folders/p5/vpnvn_w93xj0pfnhcf7mnl58rqftqf/T//RtmpXBVFuS/downloaded_packages
library(tidyverse)
library(reprex)
library(ggplot2)
ggplot(mpg, aes(displ,hwy, colour = class)) + geom_point()

svg(filename = "100218_reprex", width = 6, height = 6, pointsize = 2)
#> Warning in svg(filename = "100218_reprex", width = 6, height = 6, pointsize = 2): unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
#>   dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 6): Library not loaded: /opt/X11/lib/libcairo.2.dylib
#>   Referenced from: /Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so
#>   Reason: image not found
#> Warning in svg(filename = "100218_reprex", width = 6, height = 6, pointsize
#> = 2): failed to load cairo DLL
capabilities("cairo")
#> cairo 
#>  TRUE
sessionInfo()
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS High Sierra 10.13.6
#> 
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] reprex_0.2.1    forcats_0.3.0   stringr_1.3.1   dplyr_0.7.6    
#>  [5] purrr_0.2.5     readr_1.1.1     tidyr_0.8.1     tibble_1.4.2   
#>  [9] ggplot2_3.0.0   tidyverse_1.2.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_0.12.19     cellranger_1.1.0 pillar_1.3.0     compiler_3.5.1  
#>  [5] plyr_1.8.4       bindr_0.1.1      tools_3.5.1      digest_0.6.17   
#>  [9] lubridate_1.7.4  jsonlite_1.5     evaluate_0.11    nlme_3.1-137    
#> [13] gtable_0.2.0     lattice_0.20-35  pkgconfig_2.0.2  rlang_0.2.2     
#> [17] cli_1.0.1        yaml_2.2.0       haven_1.1.2      bindrcpp_0.2.2  
#> [21] withr_2.1.2      xml2_1.2.0       httr_1.3.1       knitr_1.20      
#> [25] fs_1.2.6         hms_0.4.2        rprojroot_1.3-2  grid_3.5.1      
#> [29] tidyselect_0.2.4 glue_1.3.0       R6_2.2.2         readxl_1.1.0    
#> [33] rmarkdown_1.10   modelr_0.1.2     magrittr_1.5     backports_1.1.2 
#> [37] scales_1.0.0     htmltools_0.3.6  rvest_0.3.2      assertthat_0.2.0
#> [41] colorspace_1.3-2 labeling_0.3     stringi_1.2.4    lazyeval_0.2.1  
#> [45] munsell_0.5.0    broom_0.5.0      crayon_1.3.4
reprex::reprex(input = "100218_RStudio_svg-help.R", outfile = "100218_RStudio_svg-help.md")

Created on 2018-10-02 by the reprex package (v0.2.1)


#7

I think this SO thread might help.