--- title: "Introduction into R markdown" author: "Vendula" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set( echo = FALSE, fig.height = 8, fig.width = 14, message = FALSE, warning = FALSE, comment = "", results = "asis", supressMessage = TRUE ) library(tidyverse) ``` ## Creating an R Markdown file Each R markddown file contains three types of text: * An (optional) YAML header surrounded by ---s * R code chunks surrounded by ```s * text mixed with simple text formatting ###YAML header * title: "...." * author: "...." * date: "...." * output: html_document/pdf_document/word_document ###Plain text formating is done using marks # Header ## Header 2 **bold** with double-asterisks _italics_ with underscores `code-type` font with backticks ###Chunk options write in the bracketes after letter "r" or as general statment e.g. knitr::opts_chunk$set(echo = TRUE) on the beginning * include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks. * echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures. * message = FALSE prevents messages that are generated by code from appearing in the finished file. * warning = FALSE prevents warnings that are generated by code from appearing in the finished. * fig.cap = "..." adds a caption to graphical results. * fig.height, fig.width * results = "markpup" or "asis" or "hide" or "hold" ### Inside chunk Sometimes is good to have formated text also inside the chunks e.g. when you create the figures or data analysis by loop * `cat` start for header * `knitr::kable()` formated table ## Printing the table ```{r table} df<-read.csv("https://course.img.cas.cz/R/material/Tiverse/mice.csv", check.names=F, stringsAsFactors = FALSE) mice_sel<-df[1:5,1:5] print(knitr::kable(mice_sel)) ``` ## Plotting the data and save them ```{r graphs } data_sel2<-df[1:22,c(1:5,38:57)] data_long3<-data_sel2%>% gather(-(ID:cohort), key = "Variable", value = "values")%>% separate(col="Variable", into=c("Var", "Time"), sep =-2)%>% mutate(Var=str_replace_all(Var,"\\s+$",replacement = "" ))%>% spread(key=Var, value = values) data_long3$Time<-as.numeric(data_long3$Time) for (i in 7:11){ data_long3$var<-data_long3[,i] p<-ggplot(data=data_long3, aes (x=Time, y=var, color=strain))+geom_smooth(method = "loess")+ facet_grid(sex~.)+theme_light() +theme(axis.text = element_text(size=12), strip.text = element_text(size=14, color="black"), axis.title=element_text(size=14,face="bold"), legend.text=element_text(size=12))+labs(y=colnames(data_long3)[i], x="Time [min]", title=colnames(data_long3)[i] ) print(p) ggsave(paste(colnames(data_long3)[i],".jpg")) } ``` ## Tasks 1. Write a sentence containing words with bold, italics, and underlined formatting. 1. Create a plot generated with 3 inches wide and 5 inches high 1. test different Chunk options for final document