Commit 2e85471c authored by Florian Huber's avatar Florian Huber

Added exercises to DataVis notebook.

parent 3f25433e
### Exercise: data import
read_csv2("../data/ImagedCells_reallife.csv")
read_csv2("../data/ImagedCells_reallife.csv", skip = 5)
read_csv2("../data/ImagedCells_reallife.csv", skip = 5, na = c("", "ERROR"))
# --------
## Exercise: aesthetics
ggplot(data = cells, aes(x = gfp_T0, y = mCh_T0)) +
geom_point(aes(shape = treated))
# Distinguish *mapping* to a colour with `aes()` from *setting* to a colour with
# commands such as `colour = "blue"`.
ggplot(data = cells, aes(x = gfp_T0, y = mCh_T0)) +
geom_point(aes(shape = treated), colour = "red") +
my_label
# This is usually not what you want: here, ggplot2 will internally create a
# new variable in the data that only contains the value "red"
ggplot(data = cells, aes(x = gfp_T0, y = mCh_T0)) +
geom_point(aes(shape = treated, colour = "red")) +
my_label
# ---------
## Exercise: model fits
ggplot(data = cells, aes(x = gfp_T0, y = mCh_T0, colour = treated)) +
geom_point() +
geom_smooth(method = "loess") +
my_label
# ---------
## Exercise: displaying error bars
gfp_summary <-
group_by(cells, Well) %>%
summarise(mean_gfp = mean(gfp_T0),
lower = mean_gfp - sd(gfp_T0),
upper = mean_gfp + sd(gfp_T0))
gfp_summary
ggplot(gfp_summary, aes(x = Well, y = mean_gfp)) +
geom_bar(stat = "identity") + # important - otherwise you'll get counts!
geom_errorbar(aes(ymin = lower, ymax = upper), width = 0.5)
# ---------
## Exercise: plotting distributions on top of each other
ggplot(cells, aes(x = gfp_T0)) +
geom_histogram(aes(fill = treated), alpha = 0.5,
position = position_fill())
# ---------
## Exercise: tidying up data
(load("../data/mtec_counts.RData"))
subtab <- mtec_counts[1:3, 1:9]
subtab
(subtab_tidy <- gather(subtab, cell17:cell25, key = "cell", value = "count"))
ggplot(subtab_tidy, aes(x = ensembl_id, y = count, fill = cell)) +
geom_bar(stat = "identity")
ggplot(subtab_tidy, aes(x = ensembl_id, y = count, fill = cell)) +
geom_bar(stat = "identity", position = "dodge")
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment