Skip to content

Instantly share code, notes, and snippets.

@kissmygritts
Created August 6, 2015 20:33
Show Gist options
  • Save kissmygritts/876f5251796f294f556a to your computer and use it in GitHub Desktop.
Save kissmygritts/876f5251796f294f556a to your computer and use it in GitHub Desktop.
Generating plots of vitals for capture reports. Decent for capture reports.
library(readxl)
library(dplyr)
library(ggplot2)
library(gridExtra)
dat <- read_excel("CalebTest.xlsx", "temp_Vitals")
## Adding color factor for temperature plot
dat$temp[dat$Metric >= 105 & dat$VitalSign == "TR"] <- "high"
dat$temp[dat$Metric < 105 & dat$VitalSign == "TR"] <- "low"
## Testing plot
p <- ggplot(data = dat, aes(x = Interval, y = Metric)) +
geom_point() +
geom_line(aes(group = factor(ndowID)))
p
## Generate split of data frame by Vital Sign (HR, TR, RR)
d <- split(dat, dat$VitalSign)
## Creating the plots
v1 <- ggplot(data = d[[1]], aes(x = Interval, y = Metric)) +
geom_point(aes(color = factor(ndowID)), size = 4) +
geom_line(aes(x = Interval, y = Metric, group = factor(ndowID), color = factor(ndowID)), size = 1) +
labs(list(title = "Animal Heart Rate", x = "Time Interval", y = "Heart Rate (beats/min)")) +
theme_bw() +
theme(panel.border = element_blank(),
legend.position = "top")
v2 <- ggplot(data = d[[2]], aes(x = Interval, y = Metric)) +
geom_point(aes(color = factor(ndowID)), size = 4) +
geom_line(aes(x = Interval, y = Metric, group = factor(ndowID), color = factor(ndowID)), size = 1) +
labs(list(title = "Animal Respiratory Rate", x = "Time Interval", y = "Respiratory Rate (breaths/min)")) +
theme_bw() +
theme(panel.border = element_blank(),
legend.position = "top")
v3 <- ggplot(data = d[[3]], aes(x = Interval, y = Metric)) +
geom_point(aes(color = factor(ndowID), shape = temp), size = 4) +
geom_line(aes(x = Interval, y = Metric, group = factor(ndowID), color = factor(ndowID)), size = 1) +
scale_y_continuous(breaks = seq(98, 109, 1)) +
labs(list(title = "Animal Temperature", x = "Time Interval", y = "Temperature (F)")) +
theme_bw() +
theme(panel.border = element_blank(),
legend.position = "top")
## Multiple plots on one sheet. Not necessary.
grid.arrange(v3, v1, v2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment