33. 꿈꾸는데이터디자이너 시즌2
ggplot() +
layer(data = iris,
mapping = aes(x = Sepal.Length,
y = Sepal.Width,
colour = Species),
geom = 'point',
stat = 'identity',
position = 'identity')
layer 함수를 이용하면
그래프를 그리는데 필요한 요소들을 레이어에 대입시킬 수 있다
ggplot2 에서는 자주 사용하는 항목을 묶어서 함수로 제공한다
Layer
35. 꿈꾸는데이터디자이너 시즌2
ggplot()+
geom_point(data = iris, aes(x=Sepal.Length, y=Sepal.Width))+
geom_smooth(data = iris, aes(x=Sepal.Length, y=Sepal.Width))
여러 개의 레이어를
겹쳐서 그릴 수 있다
36. 꿈꾸는데이터디자이너 시즌2
ggplot(data = iris, aes(x=Sepal.Length, y=Sepal.Width))+
geom_point()+
geom_smooth()
공통적으로 반영되는 요소들은 미리 정의해둘 수 있다
ggplot2의 결과물은 객체로 저장할 수 있다
iris_plot = ggplot(data = iris,
aes(x=Sepal.Length, y=Sepal.Width))
iris_plot +
geom_point()+
geom_smooth()
37. 꿈꾸는데이터디자이너 시즌2
data = diamonds
aes는 x=carat, y=price 일 때
geom_point를 사용해서 산점도(scatter plot) 그리기
44. 꿈꾸는데이터디자이너 시즌2
Position Adjustment
ggplot(mtcars,
aes(factor(cyl), fill = factor(vs))) +
geom_bar(position = "stack")
누적 막대그래프
ggplot(mtcars,
aes(factor(cyl), fill = factor(vs))) +
geom_bar(position = "fill")
누적 막대그래프
(비율)
ggplot(mtcars,
aes(factor(cyl), fill = factor(vs))) +
geom_bar(position = "dodge")
막대를 옆으로
나열한다
45. 꿈꾸는데이터디자이너 시즌2
data = diamonds
aes는 x=clarity, fill=cut 일 때
geom_bar를 사용해서 누적 막대그래프 그리기
46. 꿈꾸는데이터디자이너 시즌2
A set of layers
A set of scales
A coordinate system
A facetting specification
Guides
Data
Mapping
Statistical Transformation
Geometric Object
Position
ggplot2의 구성요소
47. 꿈꾸는데이터디자이너 시즌2
Scales
- 데이터의 값이 에스테틱에 대입되는 과정을 조절한다
- Guide(축, 범례 등)가 표시되는 방식을 결정한다
- 함수 이름은 scale_에스테틱_적용방법 으로 정해진다
60. 꿈꾸는데이터디자이너 시즌2
Facetting
두 개 이상의 변수를 지정하면
각 변수들의 경우의 수에 따라
그래프를 그려준다
ncol 옵션을 통해
한 화면에 보여지는
그래프 열의 개수를 조정한다
mtc_point +
facet_wrap(~cyl+gear, ncol = 2)