library(tidyverse)
library(googlesheets4)
library(readxl)
See https://googlesheets4.tidyverse.org/ for info on interacting directly with Google Sheets
#Import the data directly from Google Sheets
# raw_sheet_data <- read_sheet("https://docs.google.com/spreadsheets/d/1w8_xZ0OjFAKSAT77OG73cPsuSk4Jsa4YV_pQwz6DU2A/edit?ts=5e5837fc#gid=751550513",
# sheet = 2,
# range = "A2:K9")
#Alternatively, if the sheet has been downloaded as a Excel, load directly:
raw_sheet_data <- read_excel("EnzymeKineticsTempLab.xlsx",
sheet = "New (Good Temp) Data",
range = "A2:K9")
#Could also import as a csv, as you know how.
The code below makes extensive use of %>% (known as the pipe) from the magrittR package, and a variety of functions from the dplyr package. Lots more information on using these packages in the great book R for Data Science. In particular, see Chapters 5 (Data Transformation), Chapter 12 (Tidy Data), and Chapter 18 (Pipes)
tidy_kinetics <- raw_sheet_data %>%
pivot_longer(-`Temp (ËšC)`,
names_to = c("what","replicate"),
names_pattern = "(.+)\\s([0-9])") %>% #names_pattern implements a regular expression
pivot_wider(names_from = what,
values_from = value) %>%
rename(goal_temp = `Temp (ËšC)`,
obs_temp = "Temp",
v0 = "Sample") %>%
mutate(goal_temp = as_factor(goal_temp)) #here we are changing the coding of a vector from numeric to factor
tidy_kinetics
## # A tibble: 35 x 4
## goal_temp replicate obs_temp v0
## <fct> <chr> <dbl> <dbl>
## 1 20 1 22 0.870
## 2 20 2 21 0.873
## 3 20 3 20 0.798
## 4 20 4 19 0.798
## 5 20 5 20 0.798
## 6 30 1 26 0.961
## 7 30 2 26.1 0.943
## 8 30 3 26.8 0.932
## 9 30 4 26.4 0.959
## 10 30 5 24.8 0.935
## # … with 25 more rows
These functions use the pipe %>% again, along with the ggplot function from the package ggplot2. See Ch 7 in R for Data Science.
See https://www.r-graph-gallery.com/ and http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html for lots of cool plots that have been made with R.
tidy_kinetics %>%
ggplot() +
geom_point(aes(x = obs_temp, y = v0, color = goal_temp, alpha = 1)) +
labs(x="Observed temperature in the cuvette (°C)", y = "initial rate of the reaction (µM/s)") +
theme_minimal() +
NULL
tidy_kinetics %>%
ggplot() +
geom_jitter(aes(x = goal_temp, y = v0), width = .2, alpha = .5) +
labs(x="Goal temperature (°C)", y = "initial rate of the reaction (µM/s)") +
theme_minimal() +
NULL