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)
mpgcyldisphpdratwtqsecvsamgearcarb
Mazda RX421.0 6 160 110 3.90 2.62016.460 1 4 4
Mazda RX4 Wag21.0 6 160 110 3.90 2.87517.020 1 4 4
Datsun 71022.8 4 108 93 3.85 2.32018.611 1 4 1
Hornet 4 Drive21.4 6 258 110 3.08 3.21519.441 0 3 1
Hornet Sportabout18.7 8 360 175 3.15 3.44017.020 0 3 2
Valiant18.1 6 225 105 2.76 3.46020.221 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 [ ]: