R + ETC (잡동사니)

R + rayshader 그래프 (ggplot2) 2D 3D로 시각화하기

구렁이 알(Python/R) 2020. 2. 24. 17:23

필요패키지

  • library(tidyverse)

  • library(av)

  • library(rayshader)

 

 

 

"rayshader" 지도 그래프 2D 혹은 3D로 시각화하는 패키지(package) 입니다

 

 

저도 모든 기능을 아는것은 아니고 rayshader를 쓸만한 일이 많지 않아

간단히 실습만 이 페이지에서 하겠습니다

 

자세한 기능 및 code가 필요하신 분은 아래 2곳을 추천합니다

https://www.rayshader.com/

 

Create Maps and Visualize Data in 2D and 3D

Uses a combination of raytracing and multiple hill shading methods to produce 2D and 3D data visualizations and maps. Includes water detection and layering functions, programmable color palette generation, several built-in textures for hill shading, 2D and

www.rayshader.com

https://github.com/tylermorganwall/rayshader

 

tylermorganwall/rayshader

R Package for 2D and 3D mapping and data visualization - tylermorganwall/rayshader

github.com

 

 

 

 

 

 

 

 

 

 

 

#### 그래프 (ggplot2) 3D로 시각화 시각화하기

 

 

가지고 있는 데이터 중 적절한 것이 없어 기본데이터인 "diamonds"쓰겠습니다

ggdiamonds <- ggplot(diamonds) + 
  stat_density_2d(aes(x = x, y = depth, fill = stat(nlevel)),  
                  geom = "polygon",  
                  n = 100, 
                  bins = 10,  
                  contour = TRUE) + 
                  facet_wrap(clarity~.) + 
                  scale_fill_viridis_c(option = "A")

ggdiamonds를 시각화 한 plot입니다

 

다음 명령어를 실행하여 여러 값을 할당합니다(예 : zoom, theta, phi)

plot_gg(ggdiamonds, width = 5,  
                    height = 5,  
                    multicore = TRUE,  
                    scale = 250,  
                    zoom = 0.7,  
                    theta = 10,  
                    phi = 30, windowsize = c(1200, 1200))

 

 



이번에는 "orbit" 뿐만아니라 "oscillate" type으로 plot을 돌려봅시다

 

render_movie(filename = "ggdiamonds",  
             type = "orbit", 
             phi = 45,  
             theta = 60)

ggdiamonds_orbit.mp4
1.91MB

 

 

render_movie(filename = "ggdiamonds_oscillate",  
             type = "oscillate", 
             phi = 45,  
             theta = 60) 

ggdiamonds_oscillate.mp4
1.47MB

 

 

 

 

 

 

 

그리고 그래프를 3D화 하는 작업의 적절한 예시를 보여주는 사이트입니다

참고하기실 바랍니다

 

https://joeystanley.com/blog/3d-vowel-plots-with-rayshader

 

3D Vowel Plots with Rayshader

3D Vowel Plots with Rayshader August 19, 2019 So Tyler Morgan-Wall has recently come out with the rayshader package and the R and data science Twitter community has been buzzing. I’ve seen people post some absolutely amazing 3D plots and animations. I have

joeystanley.com