The captopril dataset
The captopril dataset
holds information on a small experiment with 15 patients that have increased blood pressure values. More specifically, for each patient we will have four values; one value for systolic blood pressure and one for diastolyic, both before and after treating the patient with a drug named captopril.
Import the data
library(tidyverse)
library(readr)
library(ggplot2)
Have a first look at the data
Data visualization
Let’s say we now first want to visualize the data. One possibility to easily visualize the four types of blood pressure values is by adopting the gather
function from tidyverse. It will reshape the dataframe, such that we have have a single variable type
, which points at one of the four blood pressure types, and bp
, which points at the actual value for each type for each patient.
captopril %>%
gather(type,bp,-id)
Barplot
Not all visualization types will be equally informative. Let us first make a barplot of the data. A barplot is a plot that you will commonly find in scientific publication The code for generating such a barplot is provided below:
captopril %>%
gather(type,bp,-id) %>%
group_by(type) %>%
summarize_at("bp",
list(mean=~mean(.,na.rm=TRUE),
sd=~sd(.,na.rm=TRUE),
n=function(x) x%>%is.na%>%`!`%>%sum)) %>%
mutate(se=sd/sqrt(n)) %>%
ggplot(aes(x=type,y=mean,fill=type)) +
scale_fill_brewer(palette="RdGy") +
theme_bw() +
geom_bar(stat="identity") +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),width=.2) +
ggtitle("Barplot of different blood pressure measures") +
ylab("blood pressure (mmHg)")
A barplot, however, is not very informative. The height of the bars only provides us with information of the mean blood pressure. However, we don’t see the actual underlying values, so we for instance don’t have any information on the spread of the data. It is usually more informative to represent to underlying values as raw as possible. Note that it is possible to add the raw data on the barplot, but we still would not see any measures of the spread, such as the interquartile range.
Based on this critisism, can you think of a better visualization strategy for the captopril data?
Add your proposed visualization strategy here
Descriptive statistics
- Generate a code chunk to calculate useful summary statistics for the capropril data
LS0tCnRpdGxlOiAiRXhlcmNpc2UgNC4zOiBFeHBsb3JpbmcgdGhlIGNhcHRvcHJpbCBkYXRhc2V0IgphdXRob3I6ICJMaWV2ZW4gQ2xlbWVudCBhbmQgSmVyb2VuIEdpbGlzIgpkYXRlOiAic3RhdE9taWNzLCBHaGVudCBVbml2ZXJzaXR5IChodHRwczovL3N0YXRvbWljc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