2017-04-20 19 views
1

나는 두 개의 서로 다른 기능을 가진 R에서 만든이 두 차원 그래프,이 : 나는이 두 그래프에 다음 라인과 교차를 플롯 싶습니다에서는 R에서 3 차원 그래프의 선을 그릴 수 있습니다

x <- c(0,50,100,150,200,250,300,350,400,450) 
y <- c(0,50,100,150,200,250,300,350,400,450) 
z <- c(1,2,1,1,2,1,2,1,2,1) 

plot_ly(x=x,y=y,z=z) 
scatterplot3d(x, y, z) 

을 그들 사이의 면적 :

라인 당 같이 두 그래프

Lines plotted in both graphs

+0

rgl –

+0

나는 무엇을 요구하고 있는지 분명하지 않다. 그러나 plot_ly와 scatterplot3d는 다른 방법으로 똑같이한다. 플롯에서 3D 라인을 추가하려면 data <- data.frame (x = x, y = y, z = z); plot_ly (데이터, x = ~ x, y = ~ y, z = ~ z, 유형 = 'scatter3d', 모드 = '회선') –

답변

1

를 플롯 plotly와 라인과 교차, 이런 식으로 뭔가 할 것입니다 :

library(scatterplot3d) 
library(plotly) 

x <- c(0,50,100,150,200,250,300,350,400,450) 
y <- c(0,50,100,150,200,250,300,350,400,450) 
z <- c(1,2,1,1,2,1,2,1,2,1) 
data <- data.frame(x=x,y=y,z=z) 
line <- data.frame(x = rep(200,5), y = seq(0,500,length.out = 5), z = rep(1,5)) 
line2 <- data.frame(x = rep(300,5), y = seq(0,500,length.out = 5), z = rep(1,5)) 
rect <- data.frame(expand.grid(x= c(200,300), y =c(200,300)),z = rep(1,4)) 

plot_ly() %>% 
add_trace(data=data, x=x, y=y, z=z, type="scatter3d", mode="markers") %>% 
add_trace(line, x = line$x, y = line$y, z = line$z, type = 'scatter3d', mode = 'lines', line = list(color = 'rgb(1, 1, 1)', width = 1 , dash = 'dash', width = 4)) %>% 
add_trace(line2, x = line2$x, y = line2$y, z = line2$z, type = 'scatter3d', mode = 'lines', line = list(color = 'rgb(1, 1, 1)', width = 1, dash = 'dash', width = 4)) %>% 
add_trace(line, x = line$y, y = line$x, z = line$z, type = 'scatter3d', mode = 'lines', line = list(color = 'rgb(1, 1, 1)', width = 1 , dash = 'dash', width = 4)) %>% 
add_trace(line2, x = line2$y, y = line2$x, z = line2$z, type = 'scatter3d', mode = 'lines', line = list(color = 'rgb(1, 1, 1)', width = 1, dash = 'dash', width = 4))%>% 
add_trace(rect, x=rect$x, y=rect$y, z=rect$z, type="mesh3d") 

결과를 plotly로 :

enter image description here

당신은 패키지 유형 = "L"로 lines3d() 또는 points3d()를 사용할 수
+0

정말 고마워요! 이것은 정상적으로 작동했으며 정확히 내가 필요로하는 것이 었습니다! 이 강조 표시된 영역의 전체 3D 열을 플로팅 할 수있는 방법이 있습니까? – lalatei

+0

z 축에 1에서 2까지의 음영이있는 프리즘을 플로팅하는 것을 의미합니까? –

+0

네, 그게 꼭 필요한 것입니다! – lalatei