ggplot

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 ….  

Result

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 – Diamonds

Part 2 – Scatterplot and additional plots Scatterplot with smoothed line

Scatterplot with 3rd variable and based on smoothed line x-axis = carat / y-axis = price / 3rd variable = clarity

 

To omit the grey zone