library(ggplot2)
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_point()

ggplot(mpg, aes(cty, hwy)) + geom_point()

ggplot(diamonds, aes(carat, price)) + geom_point()

ggplot(economics, aes(date, unemploy)) +geom_line()

ggplot(mpg, aes(cty)) + geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

getwd() #데이터 저장 폴더 확인
## [1] "C:/data"
setwd("c:/data")
getwd()
## [1] "c:/data"
#class라는 범례를 이용해 범주형 데이터의 색을 변형해줌
#aes는 범례를 만들어 주는 것임
ggplot(mpg, aes(displ, cty, colour = class)) + geom_point()

#colour을 블루로 지정해서 블루만 나타나게 함
ggplot(mpg, aes(displ, cty, colour = class)) + geom_point()

ggplot(mpg, aes(displ, hwy)) + geom_point(colour = "blue")

#~ <- class 별로 볼수 있도록 해줌
ggplot(mpg, aes(displ, hwy)) + geom_point() +
facet_wrap(~class)

# smooth : 선형으로 나타내줌 (후에 회귀분석 시 사용)
ggplot(mpg,aes(displ, hwy)) + geom_point() +
geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

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

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

# method = "lm" 을 통해 직선형으로 나타냄
ggplot(mpg,aes(displ, hwy)) + geom_point() +
geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'
