Exercise 3: Solutions second part

Task 2.1

Now plot them as lines and not as points using geom_line

ggplot(Orange, aes(age, circumference, color = Tree))+
  geom_line()

Task 2.2

Generate 2 objects: One plot using points and one using lines. Plot the two objects in one plot.

library(cowplot)
g1 <- ggplot(Orange, aes(age, circumference, color = Tree))+
  geom_point()
g2 <- ggplot(Orange, aes(age, circumference, color = Tree))+
  geom_line()

plot_grid(g1,g2)

Task 2.3

Add another layer to your plot: + facet_wrap(~Tree). What does the function do?

ggplot(Orange, aes(age, circumference, color = Tree))+
  geom_point()+
  geom_line()+
  facet_wrap(~Tree)

The function uses the variable Tree to make a sub-plot for each value of the variable.