library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
data("mpg")

p <- ggplot(data = mpg, aes(x=displ, y=hwy)) + 
  geom_point()
p

#ggplot(mpg, eas(displ,hwy)) +
 # geom_point()
ggplot(data = mpg) +
  geom_point(mapping = aes(x = displ, y = hwy, color = class) )

ggplot(data = mpg) +
  geom_point(mapping = aes(x = displ, y = hwy, size = class))
## Warning: Using size for a discrete variable is not advised.

# The transparency of the points
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, alpha = class))
## Warning: Using alpha for a discrete variable is not advised.

# The shape of the points
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, shape = class))
## Warning: The shape palette can deal with a maximum of 6 discrete values because
## more than 6 becomes difficult to discriminate; you have 7. Consider
## specifying shapes manually if you must have them.
## Warning: Removed 62 rows containing missing values (geom_point).

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

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point() +
  geom_smooth(se=FALSE)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point() +
  geom_smooth(method = "lm", se=FALSE)
## `geom_smooth()` using formula 'y ~ x'

##Facet wrap

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

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy)) + 
  facet_grid(drv ~ cyl)

ggplot(data = iris, mapping = aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_grid(. ~ Species) + geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'

ggplot(data = iris, mapping = aes(x=Sepal.Length,y=Sepal.Width)) + geom_point( aes(color = Species )) + geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'

g<-ggplot(data = mpg) 

 g + geom_point(mapping = aes(x = displ, y = hwy)) + 
  facet_grid(drv ~ cyl)

boxplot(mpg$hwy ~ factor(mpg$drv))

ggplot(data = mpg, mapping = aes(displ, hwy, color=drv))+
  geom_point() +
  facet_wrap(~class)

ggplot(data = mpg)+
  geom_point(aes(displ, hwy, color=fl)) +
  facet_wrap(drv~class)