Boredom exercise :)

install.packages('tidyverse')
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching packages ───────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.0     ✓ purrr   0.3.4
## ✓ tibble  3.0.1     ✓ dplyr   0.8.5
## ✓ tidyr   1.0.3     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ──────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Question 1: What’s gone wrong with this code? Why are the points not blue?

ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = “blue”))

The correct code is:

ggplot(data = mpg) +
  geom_point(mapping = aes(x = displ, y = hwy), color = "blue")

Question 2: Which variables in mpg are categorical? Which variables are continuous? (Hint: type ?mpg to read the documentation for the dataset). How can you see this information when you run mpg?

head(mpg, 1)
## # A tibble: 1 x 11
##   manufacturer model displ  year   cyl trans    drv     cty   hwy fl    class  
##   <chr>        <chr> <dbl> <int> <int> <chr>    <chr> <int> <int> <chr> <chr>  
## 1 audi         a4      1.8  1999     4 auto(l5) f        18    29 p     compact

Here, the information under ‘chr’ is categorical, whereas ‘int’ and ‘dbl’ is continuous

Question 3: Map a continuous variable to color, size, and shape. How do these aesthetics behave differently for categorical vs. continuous variables?

ggplot(data = mpg)+
  geom_point(mapping = aes(x=displ, y=hwy, col = cyl, shape = drv, size = hwy))

#### Question 4: What happens if you map the same variable to multiple aesthetics?

ggplot(data = mpg)+
  geom_point(mapping = aes(x=displ, y=hwy, col = hwy, size = hwy))

Question 5: What does the stroke aesthetic do? What shapes does it work with? (Hint: use ?geom_point)

It adjusts the thickness of plots.

Question 6: What happens if you map an aesthetic to something other than a variable name, like aes(colour = displ < 5)? Note, you’ll also need to specify x and y.

ggplot(data = mpg)+
  geom_point(mapping = aes(x=displ, y=hwy, col = displ < 5))

Questions source: https://r4ds.had.co.nz/data-visualisation.html (Exercise 3.3.1)

:)