calculate summary statistics
CD_summ <- CD_raw %>% # assign summary statistics to a new data frame
group_by(
Treatment) %>% # group data by G418 concentration
summarize( # create new data frame by summarizing grouped data
Mean = mean(Cells_cm2), # calculate the average confluence
Stdev = sd(Cells_cm2), # calculate the standard deviation
Low_CI = Mean - 2*Stdev, # calculate the low confidence interval
High_CI = Mean + 2*Stdev, # calculate the high confidence interval
)
make a bar plot showing each treatment’s mean cell density on day
7
ggplot( # create a plot using ggplot2
data = CD_summ, # use summarized cell density data
aes( # set plot aesthetics
x = Treatment, # x-axis = treatment (G418 concentration)
y = Mean # y-axis = mean cell density
)) +
geom_bar( # add bar geometries to the plot
stat = "identity", # make each treatment use its associated cell density
fill = c( # concatenate bar colors into a vector
"tomato", "gold", "forestgreen", "darkturquoise", "blue3", "deeppink"),
width = 0.8 # individual bar thickness
) +
geom_errorbar( # add error bars to the plot
aes( # set error bar aesthetics
ymin = Low_CI, # assign low confidence interval to the error bars
ymax = High_CI), # assign high confidence interval to the error bars
width = 0.2 # thickness of error bars
) +
labs( # change x and y-axis titles
x = "G418 concentration", # label x-axis
y = expression( # label y-axis; create an expression to superscript
paste( # isolate "2" from expression to superscript, paste the closed bracket after it
"Mean cell density (cells/cm"^"2", ")"
))) +
theme( # change theme elements
axis.title = element_text(size = 20), # x and y-axis text size
axis.text = element_text(size = 16), # x and y tick mark text size
axis.title.x = element_text(margin = margin(t = 15)), # x-axis title top margin
axis.title.y = element_text(margin = margin(r = 15)), # y-axis title right margin
axis.text.x = element_text(margin = margin(t = 10)), # x-axis label top margin
axis.text.y = element_text(margin = margin(r = 10)) # y-axis label right margin
) +
scale_x_discrete( # change x-axis aesthetics
labels = paste(levels(CD_raw$Treatment), # paste "µg/ml" to the end of each x-axis label
"µg/ml")
)
