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 vs ggplot2

Basic Plot with lm()

  ggplot2 with geom_smooth() method lm

In ggplot the lm() is being composed within the geom_smooth() element, and choosing “lm” (linear model).  

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