Exercise 3.2.4

This is to revise the baiscs and get rid of this boredom due to quarantine!!!

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: Run ggplot(data = mpg). What do you see?

ggplot(data = mpg)

Question 2: How many rows are in mpg? How many columns?

head(mpg)
## # A tibble: 6 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     compa…
## 2 audi         a4      1.8  1999     4 manual(m5) f        21    29 p     compa…
## 3 audi         a4      2    2008     4 manual(m6) f        20    31 p     compa…
## 4 audi         a4      2    2008     4 auto(av)   f        21    30 p     compa…
## 5 audi         a4      2.8  1999     6 auto(l5)   f        16    26 p     compa…
## 6 audi         a4      2.8  1999     6 manual(m5) f        18    26 p     compa…

6 Rows and 11 Columnss

Question 3: What does the drv variable describe? Read the help for ?mpg to find out.

?mpg

drv tells the type of drive train, where f = front-wheel drive, r = rear wheel drive, 4 = 4wd

Other Variables

Question 4: Make a scatterplot of hwy vs cyl.

ggplot(data = mpg)+
  geom_point(mapping = aes(x=hwy, y=cyl), col = 'blue')

Question 5: What happens if you make a scatterplot of class vs drv? Why is the plot not useful?

ggplot(data = mpg)+
  geom_point(mapping = aes(x=class, y=drv), col = 'red')

It is not useful because it cannot help us in drawing any logical relation.

Please don’t judge. I am doing it because of the boredom!!!! :)

Question source: https://r4ds.had.co.nz/data-visualisation.html