knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Here's the analysis for the second draft of the root figures. Changes that we talked about previously:
This vignette focuses just on the root stuff.
data("SDEF_root_data_raw") # Load raw root data. data("SDEF_root_ash_weights") # Load ash weight data. SDEF_data <- SDEF_root_data # Shorten variable name for convenience. colnames(SDEF_data) <- ifelse( colnames(SDEF_data) == "tile", "frame", colnames(SDEF_data) ) # below is old script data.root <- ConvertFrameDepth(data=data.root) data.ash <- CalculateCarbonContent(data=data.ash) # Frame height 6.75mm, frame width 9.0 mm data.root <- CalculateBioDensity(data=data.root, frame.size = c(6.75, 9.0, 0.74), scale="tube") data <- data.root biomass.convert <- c(0.21, 0.22, 0.31) names(biomass.convert) <- c("grass", "shrub", "tree") # Calculation section #### biovolume <- (pi * ((data$diameter / 2) ^ 2)) * data$length # Units in mm^3 biovolume <- biovolume / 1000 # Convert mm^3 to cm^3 convert <- vector(mode="character", length=nrow(data)) for (i in names(biomass.convert)) { convert <- sub(x=data[["veg_type"]], pattern=i, replacement=names(biomass.convert)[which(names(biomass.convert) == i)] ) } biomass <- biovolume * biomass.convert[data[["veg_type"]]] # Conversion factor is g per cm^3 # This will convert units to grams of biomass data <- data.frame(data, biovolume, biomass) data$real_depth <- data$real_depth * -1 #plot biomass library(ggplot2) library(reshape2) data_grass <- data[which(data$plot == "grass"), ] bio_plot <- ggplot(data_grass, aes(real_depth, biomass)) bio_plot <- bio_plot + stat_smooth() depth_plot <- ggplot(data_grass, aes(date, real_depth)) depth_plot <- depth_plot + geom_tile(aes(fill = biomass)) if (scale == "root") { message("Returning root-scale data... Done") return(data) } biodensity <- data.frame(matrix(ncol=6, nrow=0)) colnames(biodensity) <- c("tube", "date", "sum_biovolume", "sum_biomass", "mean_depth", "tube_biodensity") # end
Other notes from the vignette default style:
The figure sizes have been customised so that you can easily put two images side-by-side.
plot(1:10) plot(10:1)
You can enable figure captions by fig_caption: yes
in YAML:
output: rmarkdown::html_vignette: fig_caption: yes
Then you can use the chunk option fig.cap = "Your figure caption."
in knitr.
You can write math expressions, e.g. $Y = X\beta + \epsilon$, footnotes^[A footnote here.], and tables, e.g. using knitr::kable()
.
knitr::kable(head(mtcars, 10))
Also a quote using >
:
"He who gives up [code] safety for [code] speed deserves neither." (via)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.