KLI Seminar 2023
Source: The benefits of Open Science
Source
Output
Source
---
title: "ggplot2 demo"
author: "Norah Jones"
date: "5/22/2021"
format:
html:
fig-width: 8
fig-height: 4
code-fold: true
---
## Air Quality
@fig-airquality further explores the impact of temperature
on ozone level.
```{r}
#| label: fig-airquality
#| fig-cap: Temperature and ozone level.
#| warning: false
library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) +
geom_point() +
geom_smooth(method = "loess"
)
```
Output
When a project is opened within RStudio the following actions are taken:
Quarto is a command line interface (CLI) that renders plain text formats (
.qmd
,.rmd
,.md
) into static PDF/Word/HTML reports, books, websites, presentations and more
Quarto is bundled and comes pre-installed with RStudio v2022.07.1 and beyond!
quarto render
quarto
R package.qmd
.qmd
is a plain text fileThe YAML metadata or header is:
influences the final document in different ways. It is placed at the very beginning of the document and is read by each of Pandoc, Quarto and
knitr
. Along the way, the information that it contains can affect the code, content, and the rendering process.
See more formats and other YAML metadata options here
To avoid manually typing out all the options, every time!
Executing the Quarto Render button in RStudio will call Quarto render in a background job - this will prevent Quarto rendering from cluttering up the R console, and gives you and easy way to stop.
Quarto uses markdown as its underlying document syntax. Markdown is a plain text format that is designed to be easy to write, and, even more importantly, easy to read
Markdown Syntax | Output |
---|---|
|
italics and bold |
|
superscript2 / subscript2 |
|
|
|
verbatim code |
Markdown Syntax | Output |
---|---|
|
Header 1 |
|
Header 2 |
|
Header 3 |
|
Header 4 |
```{r}
# Name correction
names(data) <- gsub("d2priv", "dapriv2", names(data))
# Own function
recode_5 <- function(x) {
x * (-1)+6
}
# Use of mutate_at to apply function
data_proc <- data %>%
mutate_at(vars(matches("gattAI1_3|gattAI1_6|gattAI1_8|gattAI1_9|gattAI1_10|gattAI2_5|gattAI2_9|gattAI2_10")), recode_5)
```
In R/custom-functions.R:
Reading in your custom functions:
```{r}
data <- data[ , purrr::map_lgl(data, is.numeric)] %>% # select numeric variables
select(matches("gattAI1|soctechblind|trust1|anxty1|SocInf1|Age")) # select relevant variables
comp_split <- data %>% sjlabelled::remove_all_labels(.) %>%
split.default(sub("_.*", "", names(data))) # creating a list of dataframes, where each dataframe consists of the columns from the original data that shared the same prefix (all characters before the underscore)
comp <- purrr::map(comp_split, ~ rowMeans(.x, na.rm=T)) #calculating the row-wise mean of each data frame in the list `comp_split`, with the output being a new list (`comp`) where each element is a numeric vector of row means from each corresponding data frame in `comp_split`
comp_df <- do.call("cbind", comp) %>% as.data.frame(.) # binding all the elements in the list `comp` into a single data frame, `comp_df`
```