데이터 시각화

[R을 이용한 3D contour 쌓기] Plotly

r-code-for-data-analysis 2024. 5. 11. 22:04

Plotly를 이용하여 3D Contour 이미지 연습하기
 
https://plotly.com/r/3d-surface-plots/

 

3d

Detailed examples of 3D Surface Plots including changing color, size, log axes, and more in R.

plotly.com

 
 
마이크로 렌즈를 지나고 난 빛의 intensity 데이터

z_6.304
0.09MB

 
 
패키지 불러오기, 데이터 로드

library(tidyverse)
library(htmlwidgets)
library(plotly)


df <- read_csv("./data/z_6.304.csv", col_types = cols(.default = "n"), skip=1,col_names = F)

 
 
plotly로 3d 그래프 그리기

plot_ly(
  z = ~ scale(as.matrix(df)),
  x = ~ as.numeric(1:nrow(df)),
  y = ~ as.numeric(1:ncol(df)),
  type = "surface",
  colorbar = list(title = "My surface plot")
) %>% layout(scene = list(
  xaxis = list(title = "X-Axis"),
  yaxis = list(title = "Y-Axis"),
  zaxis = list(title = "Z-Axis")
))

 
 
적층해서 그리기

dev.off()
fig <- plot_ly(showscale = FALSE)
fig <- fig %>% add_surface(z = ~ as.matrix(df))
fig <- fig %>% add_surface(z = ~as.matrix(df+10), opacity = 0.7)
fig <- fig %>% add_surface(z = ~as.matrix(df+20), opacity = 0.7)
fig <- fig %>% add_surface(z = ~as.matrix(df+30), opacity = 0.7)
fig <- fig %>% add_surface(z = ~as.matrix(df+40), opacity = 0.7)
fig <- fig %>% add_surface(z = ~as.matrix(df+50), opacity = 0.7)

fig

 
 
html로 만들기

saveWidget(ggplotly(fig), file = "myplot.html")

 

myplot.html
4.68MB

728x90
반응형