8.4 Exercise 1

Time for our first exercise!

Starting from the same object geneexp:

  1. Create a scatter plot of sample2 (x-axis) versus sample1 (y-axis).
correction
ggplot(data=geneexp, mapping=aes(x=sample2, y=sample1)) + 
  geom_point()


2. Change the point color (blue) and size (2).

correction
ggplot(data=geneexp, mapping=aes(x=sample1, y=sample2)) + 
  geom_point(color="blue", size=2)


3. Change the point shape (“square cross”)

correction
ggplot(data=geneexp, mapping=aes(x=sample1, y=sample2)) + 
  geom_point(color="blue", size=2, shape="square cross")


4. Add a title (of your choice).

correction
ggplot(data=geneexp, mapping=aes(x=sample1, y=sample2)) + 
  geom_point(color="blue", size=2, shape="square cross") +
  ggtitle(label="my second ggplot")


5. Add a subtitle (wait: that’s new! Check ggtitle help page and/or search the internet for “ggtitle subtitle” and see if you can find!)

correction
ggplot(data=geneexp, mapping=aes(x=sample1, y=sample2)) + 
  geom_point(color="blue", size=2, shape="square cross") +
  ggtitle(label="my second ggplot", subtitle="nice blue squares")


6. Save your plot as a JPEG file, in the workshop folder, with dimensions 600X600 pixels.

correction

From the interface:

Bottom-right panel -> Plots tab -> Export -> …

From the console:

# first, save in an object
mybluescatterplot <- ggplot(data=geneexp, mapping=aes(x=sample1, y=sample2)) + 
  geom_point(color="blue", size=2, shape="square cross") +
  ggtitle(label="my second ggplot", subtitle="nice blue squares")

# then save with ggsave
ggsave(filename="myblueplot.jpg", plot=mybluescatterplot, 
       device="jpeg", 
       units="px", width=600, height=600)