--- title: Title author: Markus Kainu date: "Last updated: **`r Sys.time()`**" output: html_document: theme: yeti toc: true toc_float: true number_sections: yes code_folding: hide --- *** **Manual** Look [analysis.R](analysis.R) for the R-code and [plot](plot/)-folder for plots Below each plot you can find links for downloading the data behind the plot in .csv format and particular plot in six different formats: 1. bitmap png for screen 1. pdf vector with no fonts embedded 1. pdf vector with fonts embedded (using [`extrafont`](https://cran.r-project.org/web/packages/extrafont/index.html)-package) 1. pdf vector with fonts included as polygons (using [`showtext`](https://cran.rstudio.com/web/packages/showtext/index.html)-package) 1. svg vector 1. svg vector with fonts included as polygons (using [`showtext`](https://cran.rstudio.com/web/packages/showtext/index.html)-package) Vector formats can be edited in for example with [Inkscape](https://inkscape.org/en/) or Adobe Illustrator. Please email Markus Kainu for any further requirements regarding the graphs, eg. point sizes, dimensions, colors etc.! *** ```{r setup, knitr_setup, include=F} library(knitr) knitr::opts_chunk$set(list(echo=TRUE, eval=TRUE, cache=FALSE, warning=FALSE, message=FALSE)) opts_chunk$set(fig.width = 10, fig.height = 10) #+ setup, include=FALSE library(stringr) library(tidyverse) library(extrafont) loadfonts() library(svglite) library(showtext) library(hrbrthemes) # create folders if (!file.exists("./plot/")) dir.create("./plot/", recursive = TRUE) if (!file.exists("./data/")) dir.create("./data/", recursive = TRUE) if (!file.exists("./local_data/")) dir.create("./local_data/", recursive = TRUE) save_plot_data <- function(plot_object="p", df_name = df, figname = "fig1_vote_shares", plot_width = 11, plot_height = 8, plot_width_png = 1500, plot_height_png = 1200){ # Save data write.csv(df_name, file=paste0("./plot_csv/",figname,".csv"), row.names = F) # Save plot # png png(paste0("./plot/",figname,".png"), width=plot_width_png, height=plot_height_png, res = 150) print(get(plot_object)) graphics.off() # pdf pdf(paste0("./plot/",figname,".pdf"), width=plot_width, height=plot_height, useDingbats = FALSE, onefile = FALSE) print(get(plot_object)) graphics.off() # embed embed_fonts(file=paste0("./plot/",figname,".pdf"), outfile=paste0("./plot/",figname,"_emb.pdf")) # svg svglite(paste0("./plot/",figname,".svg"), width=plot_width, height=plot_height, standalone = TRUE) print(get(plot_object)) graphics.off() # showtext pdf & svg showtext.auto() ## automatically use showtext for new devices pdf(paste0("./plot/",figname,"_st.pdf"), width=plot_width, height=plot_height, useDingbats = FALSE, onefile = FALSE) print(get(plot_object)) graphics.off() svglite(paste0("./plot/",figname,"_st.svg"), width=plot_width, height=plot_height, standalone = TRUE) print(get(plot_object)) graphics.off() showtext.auto(FALSE) ## turn off if no longer needed } print_download_links <- function(figname){ cat(paste0( "![](plot/",figname,".png) \n", "\n", "- Download data in [.csv](./plot_csv/",figname,".csv) \n", "- Download plot in [.png](./plot/",figname,".png) \n", "- Download plot in [.pdf](./plot/",figname,".pdf) \n", "- Download plot in [.pdf](./plot/",figname,"_emb.pdf) with fonts embedded\n", "- Download plot in [.pdf](./plot/",figname,"_st.pdf) with fonts as shapes\n", "- Download plot in [.svg](./plot/",figname,".svg) \n", "- Download plot in [.svg](./plot/",figname,"_st.svg) with fonts as shapes\n" )) } ``` # Plot1 ```{r plot, knitr_setup, include=F} dat <- mtcars save_plot_data(plot_object="p", df_name = dat1, figname = paste0("fig2_4t",loop_data$var[i]), plot_width = 11, plot_height = 8, plot_width_png = 1650, plot_height_png = 1150) print_download_links(figname = paste0("fig2_4t",loop_data$var[i])) ``` # sessioninfo() ```{r sessioninfo, knitr_setup, include=F} sessionInfo() ```