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()
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")
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
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))
It adjusts the thickness of plots.
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)
:)