library(ggplot2)
library(tidyverse)
library(dplyr)
summary(mpg)
## manufacturer model displ year
## Length:234 Length:234 Min. :1.600 Min. :1999
## Class :character Class :character 1st Qu.:2.400 1st Qu.:1999
## Mode :character Mode :character Median :3.300 Median :2004
## Mean :3.472 Mean :2004
## 3rd Qu.:4.600 3rd Qu.:2008
## Max. :7.000 Max. :2008
## cyl trans drv cty
## Min. :4.000 Length:234 Length:234 Min. : 9.00
## 1st Qu.:4.000 Class :character Class :character 1st Qu.:14.00
## Median :6.000 Mode :character Mode :character Median :17.00
## Mean :5.889 Mean :16.86
## 3rd Qu.:8.000 3rd Qu.:19.00
## Max. :8.000 Max. :35.00
## hwy fl class
## Min. :12.00 Length:234 Length:234
## 1st Qu.:18.00 Class :character Class :character
## Median :24.00 Mode :character Mode :character
## Mean :23.44
## 3rd Qu.:27.00
## Max. :44.00
#display the displacement and highway mileaege
ggplot(data = mpg) + geom_point(mapping = aes(x=displ, y= hwy), color= "blue")

#for categorical data
ggplot(data = mpg) + geom_point(mapping = aes(x=displ, y= hwy, color=class)) + facet_wrap(~ class, nrow =2)

#display the displacement and number of cylinders
ggplot(data = mpg) + geom_point(mapping = aes(x=displ, y= cyl))

#to facet your plot on the combination of two variables, add facet_grid() to plot
ggplot(data = mpg) + geom_point(mapping = aes(x=displ, y= hwy)) + facet_grid(drv~cyl)
