usethis
package by running the following code in the Consoleinstall.packages("usethis")
library(usethis)
use_git_config(user.name = "Jane Doe", user.email = "jane@example.org")
git_default_branch_configure()
Clone the repository
Go to our class’s GitHub organization sta-679-s22
Find the GitHub repository (which we’ll refer to as “repo” going forward) for this lab, lab-00-tech-setup-YOUR-GITHUB-HANDLE
. This repo contains a template you can build on to complete your assignment.
https://github.com/LucyMcGowan/myrepo.git
.In this lab we will work with one package: tidyverse
which is a collection of packages for doing data analysis in a “tidy” way.
Install this package by running the following in the console.
Now that the necessary package is installed, you should be able to Knit your document and see the results.
If you’d like to run your code in the Console as well you’ll also need to load the package there. To do so, run the following in the console.
Note that the package is also loaded with the same commands in your R Markdown document.
Before we introduce the data, let’s warm up with some simple exercises.
The top portion of your R Markdown file (between the three dashed lines) is called YAML. It stands for “YAML Ain’t Markup Language”. It is a human friendly data serialization standard for all programming languages. All you need to know is that this area is called the YAML (we will refer to it as such) and that it contains meta information about your document.
Open the R Markdown (Rmd) file in your project, change the author name to your name, and knit the document.
Then Go to the Git pane in your RStudio.
If you have made changes to your Rmd file, you should see it listed here. Click on it to select it in this list and then click on Diff. This shows you the difference between the last committed state of the document and its current state that includes your changes. If you’re happy with these changes, write “Update author name” in the Commit message box and hit Commit.
You don’t have to commit after every change, this would get quite cumbersome. You should consider committing states that are meaningful to you for inspection, comparison, or restoration. In the first few assignments we will tell you exactly when to commit and in some cases, what commit message to use. As the semester progresses we will let you make these decisions.
Now that you have made an update and committed this change, it’s time to push these changes to the web! Or more specifically, to your repo on GitHub. Why? So that others can see your changes. And by others, I mean me (your repos in this course are private to you and me, only).
In order to push your changes to GitHub, click on Push.
Today we are going to read in some real data and create a figure. This data and code was generously provided by [Blythe Anderson] on GitHub.
discordant_data
. Add your responses to your lab report. When you’re done, commit your changes with the commit message “Added answer for Ex 1”, and push.discordant_data <- read_csv(
"https://raw.githubusercontent.com/blythejane/covid_safety/c92a4c60a83e67179202fafdf89858c6bafaaa7e/discordant_data.csv"
)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## case = col_character(),
## day = col_double(),
## concordance = col_logical(),
## infectious = col_logical(),
## flag_high_risk = col_logical(),
## ct_saliva = col_double(),
## ct_nasal = col_double(),
## pcr = col_character(),
## antigen = col_character(),
## manufacturer_ag = col_character(),
## molecular = col_character(),
## manufacturer_molecular = col_character()
## )
This dataset contains information about the sensitivity of nasal rapid antigen tests compared to saliva PCR tests, as detailed in this recent article.
Below is the code you will need to complete this exercise. Basically, the answer is already given, but you need to include relevant bits in your Rmd document and successfully knit it and view the results. Be sure to write a full sentence with the answer to the question (i.e. From this figure we learn…), do not only output the R code.
“CT stands for “Cycle Threshold” and indicates how many times a machine needed to try to copy a particular virus’s genetic material before being able to detect that material on a particular test called a Polymerase Chain Reaction (PCR) test. The CT value can be looked at as an indirect indicator of the amount of viral genetic material detected from a particular specimen on a particular test at a particular time. In general, a lower CT value indicates a higher viral load in that specimen, and a higher CT value indicates a lower viral load." from Santa Clara County Public Health
discordant_data <- discordant_data %>%
filter(!is.na(day), !is.na(ct_saliva))
ag_discordant <- discordant_data %>%
filter(antigen == "Negative")
ag_concordant <- discordant_data %>%
filter(antigen == "Positive")
ag_missing <- discordant_data %>%
filter(is.na(antigen))
ggplot(discordant_data, aes(day, ct_saliva)) +
geom_line(aes(group = case),
alpha = 0.8,
size = 0.6,
color = "grey55") +
geom_point(data = ag_missing,
aes(day, ct_saliva, color = "Not Performed"),
size = 1) +
geom_point(data = ag_concordant,
aes(day, ct_saliva, color = "True Positive"),
alpha = 0.5,
size = 4) +
geom_point(data = ag_discordant,
aes(day, ct_saliva, color = "False Negative"),
alpha = 0.5,
size = 4) +
scale_x_continuous("Days from first positive test",
breaks = c(0, 2, 4, 6, 8, 10)) +
scale_y_reverse("Saliva SARS-CoV-2 PCR Ct") +
scale_color_manual(values = c("False Negative" = "orangered3",
"True Positive" = "royalblue",
"Not Performed" = "grey55"),
name = "Nasal Antigen Test") +
coord_cartesian(ylim = c(38, 10), xlim = c(0, 10)) +
theme_bw()
This is another good place to pause, commit changes with the commit message “Added answer for Ex 2”, and push.
You’re done with the data analysis exercises, but we’d like you to do two more things:
Click on the gear icon in on top of the R Markdown document, and select “Output Options…” in the dropdown menu. In the pop up dialogue box go to the Figures tab and change the height and width of the figures, and hit OK when done. Then, knit your document and see how you like the new sizes. Change and knit again and again until you’re happy with the figure sizes. Note that these values get saved in the YAML.
You can also use different figure sizes for differen figures. To do so click on the gear icon within the chunk where you want to make a change. Changing the figure sizes added new options to these chunks: fig.width
and fig.height
. You can change them by defining different values directly in your R Markdown document as well.
Once again click on the gear icon in on top of the R Markdown document, and select “Output Options…” in the dropdown menu. In the General tab of the pop up dialogue box try out different Syntax highlighting and theme options. Hit OK and knit your document to see how it looks. Play around with these until you’re happy with the look.
Not sure how to use emojis on your computer? Maybe a teammate can help? Or you can ask your TA as well!
Yay, you’re done! Commit all remaining changes, use the commit message “Done with Lab 1! 💪”, and push. Before you wrap up the assignment, make sure all documents are updated on your GitHub repo.
Lab adapted from datasciencebox.org by Dr. Lucy D’Agostino McGowan