59doit
데이터 시각화 연습문제 본문
반응형
1. iris데이터 셋을 대상으로 다음 조건에 맞게 시각화 하시오
1) 1번 컬럼을 x축으로 하고 3번 컬럼을 y축으로 한다.
data(iris) plot(iris[,1],iris[,3]) ![]() |
2) 5번 컬럼으로 색상지정한다.
plot(iris[,1], iris[,3], col=iris[,5]) ![]() |
names(iris) plot(iris$Sepal.Length, iris$Petal.Length, col=iris$Species) ![]() |
3) 차트 제목을 “iris 데이터 산포도”로 추가한다.
title(main="iris 데이터 테이블 산포도 차트") ![]() |
![]() |
4) 다음 조건에 맞추어 작성한 차트를 파일에 저장한다.
- 작업 디렉토리: “C:/Rwork/output”
- 파일명: “iris.jpg”
- 크기: 폭(720픽셀), 높이(480픽셀)
setwd("C:/Rwork/output") # 작업 디렉터리 지정 jpeg("iris.jpg", width=720, height=480) # 픽셀 지정 가능 plot(iris[,1], iris[,3], col=iris[,5]) title(main="iris 데이터 테이블 산포도 차트") dev.off() # 장치 종료 |
2. iris3 데이터 셋을 대상으로 다음 조건에 맞게 산점도를 그리시오
1) iris3 데이터 셋의 컬럼명을 확인한다.
data(iris3) attributes(iris3) # $dim # [1] 50 4 3 # # $dimnames # $dimnames[[1]] # NULL # # $dimnames[[2]] # [1] "Sepal L." "Sepal W." "Petal L." "Petal W." # # $dimnames[[3]] # [1] "Setosa" "Versicolor" "Virginica" |
2) iris3 데이터 셋의 구조를 확인한다.
str(iris3) # num [1:50, 1:4, 1:3] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # - attr(*, "dimnames")=List of 3 # ..$ : NULL # ..$ : chr [1:4] "Sepal L." "Sepal W." "Petal L." "Petal W." # ..$ : chr [1:3] "Setosa" "Versicolor" "Virginica" |
#3차원 배열 형태
, , Setosa Sepal L. Sepal W. Petal L. Petal W. [1,] 5.1 3.5 1.4 0.2 [2,] 4.9 3.0 1.4 0.2 ... , , Versicolor Sepal L. Sepal W. Petal L. Petal W. [1,] 7.0 3.2 4.7 1.4 [2,] 6.4 3.2 4.5 1.5 ... , , Virginica Sepal L. Sepal W. Petal L. Petal W. [1,] 6.3 3.3 6.0 2.5 [2,] 5.8 2.7 5.1 1.9 ... |
3) 꽃의 종별로 산점도 그래프를 그린다.
# iris3[,,1] # "Setosa" # iris3[,,2] # "Versicolor" # iris3[,,3] # "Virginica" # colnames(iris3) # "Sepal L." "Sepal W." "Petal L." "Petal W." Setosa <- as.data.frame(iris3[,,1]) Versicolor <- as.data.frame(iris3[,,2]) Virginica <- as.data.frame(iris3[,,3]) max_Set <- max(Setosa)+2.5 min_Set <- min(Setosa) max_Ver <- max(Versicolor) min_Ver <- min(Versicolor) max_Vir <- max(Virginica) min_Vir <- min(Virginica) library(scatterplot3d) d3 <- scatterplot3d(Setosa$'Petal L.', Setosa$'Sepal L.', Setosa$'Sepal W.', type = 'n', xlim=c(min_Set,max_Set), ylim=c(min_Ver,max_Ver), zlim=c(min_Vir,max_Vir), main="iris3 데이터 셋의 종별분포현황") d3$points3d(Setosa$'Petal L.', Setosa$'Sepal L.', Setosa$'Sepal W.', bg = 'orange', pch = 21) d3$points3d(Versicolor$'Petal L.', Versicolor$'Sepal L.', Versicolor$'Sepal W.', bg = 'blue', pch = 23) d3$points3d(Virginica$'Petal L.', Virginica$'Sepal L.', Virginica$'Sepal W.', bg = 'green', pch = 25) |
반응형
'Q.' 카테고리의 다른 글
[ R ] 화면설계 예제 TEST (10) (0) | 2022.12.25 |
---|---|
[ R ] 다양한 시각화 문제 (0) | 2022.12.24 |
토픽 모델링 연습문제 (2) | 2022.12.21 |
비교분석 연습문제 (0) | 2022.12.19 |
텍스트 분석 연습문제 (0) | 2022.12.16 |
Comments