qplot
Why qplot???
qplot makes it easy to
produce complex plots, often requiring several lines of code using other plotting
systems, in one line. qplot() can do this because it's based on the grammar
of graphics, which allows you to create a simple, yet expressive, description
of the plot.
"ggplot2, Hadely wickham"
1. qplot
qplot( x, y, data, geom, facets, colour.fill)
1.1) Colour, Shape
qplot(carat, price, data = diamonds, colour = color )
qplot(carat, price, data = diamonds, shpae= color )
1.2) Transparency
qplot(carat, price, data =diamonds, alpha = I(1/20))
alpha : 투명도
data가 많을 때, 그냥 plot으로 그릴 경우 한눈에 들어오지 않음
1.3) Add Smooth line to chart
qplot(carat, price, data = sample_n(diamonds,1000) , geom = c("point", "smooth"),
span = 0.2)
span : wiggly (구불거림의 정도 설정)
sample_n : dplyr package
sample size가 클경우 아래 방식을 사용 ( n > 1000)
library(mgcv)
qplot(carat, price, data = dsmall, geom = c("point", "smooth"),
method = "gam", formula = y ~ s(x))
qplot(carat, price, data = dsmall, geom = c("point", "smooth"),
method = "gam", formula = y ~ s(x, bs = "cs"))
library(splines)
qplot(carat, price, data = dsmall, geom = c("point", "smooth"),
method = "lm")
fits linear model
qplot(carat, price, data = dsmall, geom = c("point", "smooth"),
method = "lm", formula = y ~ ns(x,5))
fits natural spline line