Exercises: Session 2¶
In [7]:
suppressPackageStartupMessages(library(tidyverse))
Warning message:
“Installed Rcpp (0.12.12) different from Rcpp used to build dplyr (0.12.11).
Please reinstall dplyr to avoid random crashes or undefined behavior.”Warning message:
“package ‘dplyr’ was built under R version 3.4.1”
In [1]:
head(mtcars)
mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb | |
---|---|---|---|---|---|---|---|---|---|---|---|
Mazda RX4 | 21.0 | 6 | 160 | 110 | 3.90 | 2.620 | 16.46 | 0 | 1 | 4 | 4 |
Mazda RX4 Wag | 21.0 | 6 | 160 | 110 | 3.90 | 2.875 | 17.02 | 0 | 1 | 4 | 4 |
Datsun 710 | 22.8 | 4 | 108 | 93 | 3.85 | 2.320 | 18.61 | 1 | 1 | 4 | 1 |
Hornet 4 Drive | 21.4 | 6 | 258 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 | 1 |
Hornet Sportabout | 18.7 | 8 | 360 | 175 | 3.15 | 3.440 | 17.02 | 0 | 0 | 3 | 2 |
Valiant | 18.1 | 6 | 225 | 105 | 2.76 | 3.460 | 20.22 | 1 | 0 | 3 | 1 |
1. Make a scatter plot with y=mpg
and x=wt
In [ ]:
2. Add a linear regression curve.
3. Add a title ‘Fuel efficiency decreases with weight’, and rename the x and y axis to ‘Weight’ and ‘Miles per gallon’.
In [ ]:
4. Change the color of the scatter points to salmon
.
In [ ]:
5. Change the color of the scatter points to represent the
horsepower hp
.
In [ ]:
6. Use color brewer to set the scale in Q4 with the Oranges
sequential palette for the cyl
variable.
In [ ]:
7. Make a density plot of mpg
and fill by the factor cyl
,
and set the transparency to 0.5.
In [ ]:
8. Repeat Q7, but use 3 separate plots. Remove the legend.
In [ ]:
9. Create a scatter plot -log(p value) on the y-axis and SNP
location on the x-axis, coloring by chromosome number. This is known as
a Manhattan plot. Use the code below to simulate data for the plot. Use
the Set3
palette of qual
type in scale_color_brewer
for the
color scheme.
n <- 10000 # number of genes
position <- 1:n
chromosome <- factor(rep(1:10, each=n/10))
p.value <- runif(n)
df <- data.frame(position=position, chromosome=chromosome, p.value=p.value)
In [ ]: