Loading the necessary packages and getting the data:
setwd("C:/Users/uroy/Dropbox/personal")
library(tidyverse)
library(readxl)
library(lubridate)
library(plotly)
bp <- read_xlsx(
path = "C:/Users/uroy/Dropbox/personal/blood-pressure/blood-pressure-Omron.xlsx",
range = "A1:D300",
col_names = TRUE
)
p2 <- ggplot(bp, aes(x = Date)) +
geom_line(aes(y = Sys, colour = "Sys")) +
geom_line(aes(y = Dia, colour = "Dia")) +
labs(x = NULL, y = NULL)
ggplotly(p2)
bp_long <- bp %>%
pivot_longer(c("Sys", "Dia"), names_to = "Measure", values_to = "Amount")
p3 <- ggplot(bp_long, aes(x = Date, y = Amount, colour = Measure)) +
geom_line() +
labs(x = NULL, y = NULL)
ggplotly(p3)
p4 <- group_by(bp_long, day = wday(Date, label = TRUE), Measure) %>%
summarise(mean = mean(Amount, na.rm = TRUE)) %>%
ggplot(aes(x=day, y=mean, fill = Measure)) +
geom_bar(stat="identity", position = "dodge")
ggplotly(p4)
readxl::read_xlsx() to import data from Excel
(.xlsx) filesggplot2ggplot2 (two methods)dplyr::pivot_longer() to convert non-tidy data to
tidy datalubridate::wday() to extract the day of the week
from a dategroup_by() and summarize() in tandem
to extract averages of groupscor() to calculate Pearson’s correlation
coefficientThe End