### First Graphs – Scatterplot 2 variables

1 2 3 |
library(ggplot2) ggplot(mtcars, aes(x=cyl, y = mpg)) + geom_point() |

1 2 3 4 5 |
library(ggplot2) # Change the command below so that cyl is treated as factor ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_point() |

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 be hard to distinct, size is not precise as a value on the x/y axis).

1 2 3 4 5 |
ggplot(mtcars, aes(x = wt, y = mpg, color = disp)) + geom_point() ggplot(mtcars, aes(x = wt, y = mpg, size = disp)) + geom_point() |

Graphs in R / ggplot2