Graphs in R / Aesthetics in ggplot2

ggplot2 – the aes() element in ggplot The aim is to have a clear plot of your data. Here some examples :

  Plots with a clear output Plot 1,2,3, 6 and 11   Plots with confusing elements Plot

Graphs in R / Data formatting

Working with tidyr package A dataset is ‘tidy’ when every row is 1 observation A dataset is ‘wide’ when a row contains more observations In R tidyr package ….  


In Plots

 With the wide dataset

Graphs in R / Basic Plot function – linear model

Basic Plot – linear model with abline() Plot 1 – linear model all datapoints

  Plot 2 – linear model per subset Add library(graphics) to the code for the legend() function

Use of lapply –> take the vector

Graphs in R / ggplot2

First Graphs – Scatterplot 2 variables

The x-axis is now handled as factor. Graphs РScatterplot with 3 variables This can be done by either add a color or a size. But this is not optimal ( colors can