```r
library(ggplot2)
ggplot(data = mpg) + geom_smooth(mapping=aes(x=displ,y=hwy,linetype=drv))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

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

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

ggplot(data = mpg) + geom_smooth(mapping=aes(x=displ, y=hwy, color=drv), show.legend = FALSE)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

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

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(mapping = aes(color = class)) + geom_smooth(data =dplyr::filter(mpg, class == "subcompact"), se = TRUE)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(mapping = aes(color = class)) + geom_smooth(data =dplyr::filter(mpg, class == "minivan"), se = TRUE)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at 4.008
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.708
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : There are other near singularities as well. 0.25
## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
## else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used at
## 4.008
## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
## else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
## 0.708
## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
## else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : reciprocal condition
## number 0
## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
## else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : There are other near
## singularities as well. 0.25

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point(mapping = aes(color = class)) + geom_smooth(data =dplyr::filter(mpg, class == "2seater"), se = FALSE)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : span too small.  fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at 5.6935
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.5065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : There are other near singularities as well. 0.65044

ggplot(data = diamonds, mapping = aes(x = carat, y = price)) + geom_point(mapping = aes(color = cut))

ggplot(data = diamonds, mapping = aes(x = carat, y = clarity)) + geom_point(mapping = aes(color = price))

hist(diamonds$price, main = "History of diamonds cost", xlab = "Price")

var(diamonds$carat)
## [1] 0.2246867
var(diamonds$price)
## [1] 15915629
sd(diamonds$carat)
## [1] 0.4740112
sd(diamonds$price)
## [1] 3989.44
table(diamonds$cut)
## 
##      Fair      Good Very Good   Premium     Ideal 
##      1610      4906     12082     13791     21551
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, color = cut))

ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, fill = cut))

ggplot(data = diamonds) + geom_bar(mapping =aes(x = cut, fill = clarity))

ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge")

nz<-map_data("nz")
usa<-map_data("usa")
ggplot(nz, aes(long, lat, group = group)) + geom_polygon(fill = "blue", colour = "black") + coord_quickmap()

ggplot(usa, aes(long, lat, group = group)) + geom_polygon(fill = "red", colour = "black") + coord_quickmap()