In this post, we will learn how to add simple regression line in three different ways to a scatter plot made with ggplot2 in R. This is something I have to google almost every time, so here is the post recording the options to add linear regression line. We will use palmer penguin data to […]
R Tips
dplyr matches(): select columns using regular expression
This quick post has an example using a neat dplyr function matches() to select columns using regular expressions. dplyr has a number of helper functions, contains(), starts_with() and others, for selecting columns based on certain condition. For example if you interested selecting columns based on how its starts with we can use start_with() function. However, […]
How to create a list of plot objects and save them as files
In this post, we will learn a really nice trick on creating multiple ggplots from a dataframe and saving the plots into files using ggsave, using tidyverse purrr’s magic. We will use Purrr’s map function to create multiple plots from a dataframe and use another Purrr function pwalk to save the plots as files. Learned […]
On the effect of sample sizes on Sample Variance
Often we work with datasets of small sample sizes and rely on sample variances estimated from such datasets. One thing I have come across multiple times is that we lack the intuition/sense of how unreliable our sample variance estimates from data sets of small sample size can be. And I resort to a quick simulated […]
How to write a simple custom ggplot theme from scratch
In this post, we will learn how to write your first custom ggplot2 theme and show how to use it to make the plots slightly easier/better. ggplot2 offers us great control to customize a plot. In earlier posts we saw how to use different theme elements, element_text(), element_line(), element_rect(), element_blank() to change to customize a […]