Calmcode - ggplot: mental modes

Mental Modes

1 2 3 4 5 6 7 8

Make sure that the following libraries are loaded before running other code.


This is the final code snippet for this series.

agg_df <- ChickWeight %>%
  group_by(Diet, Time) %>%
  summarise(m = mean(weight))

ggplot() +
  geom_point(data=ChickWeight, aes(x=Time, y=weight), alpha=0.7) +
  geom_line(data=agg_df, aes(x=Time, y=m, color=Diet)) +
  ggtitle("Growth of Chicken Weight",
          subtitle="Lines show mean weight. Note the variance.")

Final Notes

If you're interested in learning more, feel free to check the ggplot2 documentation.

If you're wondering how to do similar charts in python, you might want to check out plotnine. The project tries to offer an API similar to ggplot2 in python. There are some differences between R and python so the API isn't 100% compatible, but it might be worth a look if you like what you saw here.