8.4 Exercise 1
Time for our first exercise!
Starting from the same object geneexp:
- Create a scatter plot that shows sample2 on the x-axis and sample1 on the y-axis.
2. Change the point color to blue, and the point size to 2.
correction
3. Change the point shape to “square cross”
correction
ggplot(data=geneexp, mapping=aes(x=sample1, y=sample2)) +
geom_point(color="blue", size=2, shape="square cross")
4. Add the 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! Google check ggtitle help page and/or “ggtitle subtitle” and see if you can find out!)
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 course 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)