We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.
Using the untidy data (SACTN2) and the tidy data (SACTN2_tidy), create line graphs, one for each of DEA, SAWS, and KZNSB, showing a time series of temperature. Ensure you have a column of three figures (ncol = 1). Use the fewest number of lines of code possible. You should end up with two graphs, each with three panels. (/13)
Answer
library(tidyverse)load("../data/SACTN_mangled.RData") # ✓SACTN2_tidy <-pivot_longer(SACTN2, cols =c("DEA", "KZNSB", "SAWS"),names_to ="src",values_to ="temp") # ✓# Starting with SACTN2: one could be sneaky and cheat by using# 'pivot_wider()' in the pipelineSACTN2 |># ✓ x 6pivot_longer(cols =c("DEA", "KZNSB", "SAWS"),names_to ="src",values_to ="temp") |>ggplot(aes(x = date, y = temp)) +geom_line(aes(col = site, linetype = type)) +facet_wrap(~ src, ncol =1) +labs(title ="Untidy Data", # ✓x ="Date", y ="Temperature (°C)")
# For the untidy data, above, I'll also allocate marks if you insisted in # creating more work for yourself by doing it the long way.... ( # ✓ x 7)# Starting with SACTN2_tidy# (creates an identical plot)ggplot(data = SACTN2_tidy, aes(x = date, y = temp)) +# ✓ x 4geom_line(aes(col = site, linetype = type)) +facet_wrap(~ src, ncol =1) +labs(title ="Tidy Data", # ✓x ="Date", y ="Temperature (°C)")
---title: "BCB744 Bonus Task"format: html: fig-format: svg fig_retina: 2 fig-dpi: 400params: hide_answers: false---# [[Assessment Sheet](BCB744_Task_Bonus_Surname.xlsx)]{.my-highlight} {#sec-assessment}# 12--14. Tidy Data## Question 1What are the key principles of tidy data? **(/3)**`r if (params$hide_answers) "::: {.content-hidden}"`**Answer**- ✓ Each variable forms a column.- ✓ Each observation forms a row.- ✓ Each type of observational unit forms a table.```{r, echo=FALSE,eval=FALSE,warning=FALSE,message=FALSE,fig.width=6,fig.asp=0.65,out.width="80%",fig.align='center'}````r if (params$hide_answers) ":::"`## Question 2Using the untidy data (`SACTN2`) and the tidy data (`SACTN2_tidy`), create line graphs, one for each of DEA, SAWS, and KZNSB, showing a time series of temperature. Ensure you have a column of three figures (ncol = 1). Use the fewest number of lines of code possible. You should end up with two graphs, each with three panels. **(/13)**`r if (params$hide_answers) "::: {.content-hidden}"`**Answer**```{r, echo=TRUE,eval=TRUE,warning=FALSE,message=FALSE,fig.width=6,fig.asp=0.65,out.width="80%",fig.align='center'}library(tidyverse)load("../data/SACTN_mangled.RData") # ✓SACTN2_tidy <-pivot_longer(SACTN2, cols =c("DEA", "KZNSB", "SAWS"),names_to ="src",values_to ="temp") # ✓# Starting with SACTN2: one could be sneaky and cheat by using# 'pivot_wider()' in the pipelineSACTN2 |># ✓ x 6pivot_longer(cols =c("DEA", "KZNSB", "SAWS"),names_to ="src",values_to ="temp") |>ggplot(aes(x = date, y = temp)) +geom_line(aes(col = site, linetype = type)) +facet_wrap(~ src, ncol =1) +labs(title ="Untidy Data", # ✓x ="Date", y ="Temperature (°C)")# For the untidy data, above, I'll also allocate marks if you insisted in # creating more work for yourself by doing it the long way.... ( # ✓ x 7)# Starting with SACTN2_tidy# (creates an identical plot)ggplot(data = SACTN2_tidy, aes(x = date, y = temp)) +# ✓ x 4geom_line(aes(col = site, linetype = type)) +facet_wrap(~ src, ncol =1) +labs(title ="Tidy Data", # ✓x ="Date", y ="Temperature (°C)")````r if (params$hide_answers) ":::"`