-
[R 통계_ggplot2 패키지] 01. 점 그래프(geom_point) 그리기R 패키지/ggplot2 2021. 9. 19. 18:23728x90
ggplot2 패키지를 이용해 다양한 점 그래프를 그려보자.
1-1. 점 그래프 (기본형)
그래프1 <- ggplot(데이터명, aes(x축, y축))
그래프1 <- 그래프1 + geom_plot()
library(ggplot2) head(mtcars) #01-1. 점 그래프 (기본) plot_graph_layer1 <- ggplot(mtcars, aes(x = mpg, y = disp)) plot_graph1 <- plot_graph_layer1 + geom_point() plot_graph1
geom_point 기본형태 1-2. 점 그래프 (크기와 색상선택)
그래프2 <- ggplot(데이터명, aes(x축, y축))
그래프2 <- 그래프2 + geom_plot(colour = "색상명", size = 숫자)
library(ggplot2) head(mtcars) #01-2. 점 그래프 (크기와 색상선택) plot_graph_layer2 <- ggplot(mtcars, aes(mpg, disp, colour=cyl)) plot_graph2 <- plot_graph_layer2 + geom_point(colour="blue", size = 4) plot_graph2
geom_point with colour and size 1-3. 점 그래프 (색상 변수 추가)
그래프3 <- ggplot(데이터명, aes(x축, y축), colour = 색상변수)
그래프3 <- 그래프3 + geom_plot(size = 숫자)
library(ggplot2) head(mtcars) #01-3. 점 그래프 (색상 변수 추가) plot_graph_layer3 <- ggplot(mtcars, aes(mpg, disp, colour=cyl)) plot_graph3 <- plot_graph_layer3 + geom_point(size = 4) plot_graph3
geom_point with colour variation 1-4. 점 그래프 (색상 변수 추가)
그래프4 <- ggplot(데이터명, aes(x축, y축))
그래프4 <- 그래프4 + geom_plot(aes(colour = 색상변수, size = 크기변수))
library(ggplot2) head(mtcars) plot_graph_layer4 <- ggplot(mtcars, aes(mpg, disp)) plot_graph4 <- plot_graph_layer4 + geom_point(aes(colour = factor(gear), size = wt)) plot_graph4
geom_point with colour variation and size variation 728x90'R 패키지 > ggplot2' 카테고리의 다른 글
[R 통계_ggplot2 패키지] 03. geom_boxplot으로 박스플롯 만들기 (0) 2021.09.25 [R 통계_ggplot2 패키지] 02. geom_bar로 막대차트 만들기 (0) 2021.09.22 [R 통계_ggplot2 패키지] 01-2. geom_point에 stat_function으로 맞춤형 식 추가하기 (0) 2021.09.21 [R 통계_ggplot2 패키지] 01-1. geom_point에 회귀선(geom_abline) 추가하기 (0) 2021.09.20 [R 통계_ggplot2 패키지] 00. ggplot 패키지의 문법 구성 (0) 2021.09.18