Automated Markdown sections

Just remember to remove the ` ` around the ```. I had to put them in there to make sure it didn’t run as a code block. (I’m sure there’s an easier way to do it)

` ```{r, results="asis",echo=T} `
biomes <- c("Fynbos","SucculentKaroo","AlbanyThicket","Renosterveld","Grassland","Savanna")
for (ibiome in biomes) { 
  cat(" \n#", ibiome,"\n") 
  cat( "\n### Distribution\n") 
  # DO Someting Cool ``
} 
` ``` `

Google sheets download

library(googlesheets)
library(dplyr)
gs_database <- gs_title("Sheet_Name") # No extension
gs_database%>%
   gs_read(ws = "WorksheetName")->
   dat

Personalised working directories

Courtesy of Jasper Slingsby and Glenn Moncrieff (can’t remember which of these two actually showed me this…)

For when you share a script on Dropbox…

if(Sys.getenv("USERNAME") == "apotts") datwd <-"D:/Dropbox/Project96783WhenWillItEnd/Data"
if(Sys.getenv("USERNAME") == "studentX") datwd <-"D:/Dropbox/MyProject/WhereMyStuffLives/MaybeThisIsImporant/Version2/Version3ofVersion2/Data"
setwd(datwd)

Plotting multiple plots on a single figure

Courtesy of Jasper Slingsby. Not the neatest example, but the general capabilities are shown.

library(ggplot2)
library(cowplot)

fg1 <- ggplot(mpg, aes(class)) + geom_bar(aes(fill = drv))
fg2 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()

fig <- ggdraw() +
  draw_plot(fg1 + theme(legend.position=c(.85,.25), legend.key.size=unit(.5, "cm")), x = 0, y = 0.5, width = .33, height = 0.5) +
  draw_plot(fg1 + theme(legend.position="none"), x = .33, y = 0.5, width = .33, height = 0.5) +
  draw_plot(fg1 + theme(legend.position="none"), x = .66, y = 0.5, width = .33, height = 0.5) +
  draw_plot(fg2, x = 0, y = 0, width = .33, height = 0.5) +
  draw_plot(fg2, x = .33, y = 0, width = .33, height = 0.5) +
  draw_plot(fg2, x = .66, y = 0, width = .33, height = 0.5) +
  draw_plot_label(label = c("(A)", "(B)", "(C)", "(D)", "(E)", "(F)"), size = 15, x = c(0.02, 0.35, 0.68, 0.02, 0.35, 0.68), y = c(.95, .95, .95, .45, .45, .45)) #, fontface = "bold")
fig

ggsave(fig,...)