Homework 5: Visualize anything with ggplot2
QUESTION for Jenny: when I am making figures for a paper in colour, and nearing the final version, I often want to also know what they are going to look like when printed in black and white. Is there an easier way to do this to have a quick look rather than printing to pdf and then in adobe printing again to pdf in B&W? Thanks!
For this homework I chose to work on some of my own data that I am in the middle of preparing for a conference.
The baseline data is taken while subjects are supine and breathing through a mask and sensor so that we can get their baseline oxygen and carbon dioxide levels. I have a figure of this, but I coulnd't figure out how to embed it in the RMarkdown document (all of the examples are images that are linked somewhere on the web…).
library(ggplot2)
library(plyr)
## import data
setwd("~/Rwork/ETF/Ranalyses")
meanBLData <- read.csv("ETFMeanBLData")
ETFData <- read.csv("ETFCO2Data")
modETFData <- read.csv("modETFData")
Baseline data
The baseline data will be static values best represented in a strip plot format I think. The grouping variable will be the experimental group that individuals fall in (control, complete spinal cord injury, and incomplete spinal cord injury)
This plot shows resting supine blood pressure (both systolic (black) and diastolic (red)). There is no clear difference between the groups. Individuals with complete high level spinal cord injury typically have low resting blood pressure - so the high values in the complete group should be verified. It is possible that the differences in blood pressure that are normally reported are mitigated once individuals are lying down (ie the normal differences in blood pressure have to do with being in the upright position where blood is pooling in the paralysed extremities).
ggplot(meanBLData, aes(x = group, y = blSAP)) + geom_point(position = position_jitter(w = 0.05)) +
geom_point(data = meanBLData, aes(x = group, y = blDAP, colour = "#000099"),
position = position_jitter(w = 0.05)) + opts(legend.position = "none")
## 'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in
## version 0.9.1)
Cerebral Blood Flow and Carbon Dioxide The main point of this experiment is to look at how the cerebral blood flow is affected by the levels of carbon dioxide(CO2). We manipulate CO2 by having individuals hyperventilate (this lowers CO2) and hypoventilate (this happens naturally at the end of hyperventilation - people breathe less often afterwards). Finally, we are using an end-tidal forcing system that allows us to increase CO2 to a high range (subjects breathe through a bag that we can fill with air of a variety of different gas compositions - more or less O2 and CO2).
Some research groups have shown that this is a linear relationship - while others argue that it is a segmented linear relationship - and still others treat the relationship as sigmoidal. Therefore, I am planning to fit each of these kinds of lines and record the goodness of fit. For the moment, I have just plotted the linear relationship.
In the following graph, each panel represents one group. Each line represents one subject. The relationship between the end-tidal carbon dioxide (ETCO2) and middle cerebral artery mean velocity (MCAint) is plotted.
modETFData$subject <- as.factor(modETFData$subject)
ggplot(modETFData, aes(x = ETCO2, y = MCAint, color = subject)) + geom_point() +
geom_smooth(aes(group = subject), method = "lm") + facet_wrap(~group) +
opts(legend.position = "none")
## 'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in
## version 0.9.1)
## Warning: Removed 2 rows containing missing values (stat_smooth). Warning:
## Removed 1 rows containing missing values (stat_smooth). Warning: Removed 8
## rows containing missing values (stat_smooth). Warning: Removed 4 rows
## containing missing values (stat_smooth). Warning: Removed 2 rows
## containing missing values (stat_smooth). Warning: Removed 2 rows
## containing missing values (geom_point). Warning: Removed 13 rows
## containing missing values (geom_point). Warning: Removed 2 rows containing
## missing values (geom_point).
These are a bit hard to interpret - I think that without the standard devation to the line it might be better.
ggplot(subset(modETFData, group == "complete"), aes(x = ETCO2, y = MCAint, colour = subject)) +
geom_point() + geom_smooth(aes(group = subject), method = "lm", se = FALSE)
## Warning: Removed 2 rows containing missing values (stat_smooth). Warning:
## Removed 2 rows containing missing values (geom_point).