본문 바로가기
공부/R Programming

R 기초; ggplot2 그래픽1 - 구조와 그래프 생성

by 혼밥맨 2021. 1. 24.
반응형

R 기초; ggplot2 그래픽1 - 구조와 그래프 생성

 

R의 그래픽 시스템과 ggplot2

 - 베이스 그래픽 시스템 (base graphics system) vs. 그리드 그래픽 시슽메 (grid graphics system)

 - ggplot2 패키지

 : 저수준의 그리드 그래픽 시스템을 기반으로 다양한 고수준 그래픽 구현

 : 'gg'는 'grammar of graphics'를 의미

 : 그래프 문법 구조를 바탕으로 통일된 규칙에 따라 일관된 방식으로 그래프를 생성

 

 

install.packages("ggplot2")

library(ggplot2)

 

ggplot(data=mtcars, aes(x=wt, y=mpg)) + geom_point() + labs(title="Fuel consumption vs. Weight",

         x = "weight", y = "Fuel Consumption")

 

data(mtcars)

mtcars$cyl <- factor(mtcars$cyl, levels=c(4, 6, 8), labels=c("4 Cylinders", "6 cylinders")

 

ggplot(data=mtcars, aes(x=mpg)) + geom_histogram() + facet_grid(cyl ~ .) + labs(title="geom_histogram()", x="Miles per Gallon")

 

...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형

댓글