Skip to content

Commit 77ce576

Browse files
committed
fixed aspect ratio example for R
1 parent a5b97a7 commit 77ce576

File tree

2 files changed

+118
-5
lines changed

2 files changed

+118
-5
lines changed

_posts/r/layout/2017-01-04-3d-axes.Rmd

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,63 @@ chart_link
7272
chart_link
7373
```
7474

75+
### Fixed Ratio Axes
76+
77+
```{r, results = 'hide'}
78+
library(plotly)
79+
80+
# custom grid style
81+
axx <- list(
82+
gridcolor='rgb(255, 255, 255)',
83+
zerolinecolor='rgb(255, 255, 255)',
84+
showbackground=TRUE,
85+
backgroundcolor='rgb(230, 230,230)'
86+
)
87+
88+
# individual plots
89+
p1 <- plot_ly(z = ~volcano, scene='scene1') %>%
90+
add_surface(showscale=FALSE)
91+
92+
p2 <- plot_ly(z = ~volcano, scene='scene2') %>%
93+
add_surface(showscale=FALSE)
94+
95+
p3 <- plot_ly(z = ~volcano, scene='scene3') %>%
96+
add_surface(showscale=FALSE)
97+
98+
p4 <- plot_ly(z = ~volcano, scene='scene4') %>%
99+
add_surface(showscale=FALSE)
100+
101+
# subplot and define scene
102+
p <- subplot(p1, p2, p3, p4) %>%
103+
layout(title = "3D Subplots",
104+
scene = list(domain=list(x=c(0,0.5),y=c(0.5,1)),
105+
xaxis=axx, yaxis=axx, zaxis=axx,
106+
107+
# select the type of aspectmode
108+
aspectmode='cube'),
109+
scene2 = list(domain=list(x=c(0.5,1),y=c(0.5,1)),
110+
xaxis=axx, yaxis=axx, zaxis=axx,
111+
aspectmode='data'),
112+
scene3 = list(domain=list(x=c(0,0.5),y=c(0,0.5)),
113+
xaxis=axx, yaxis=axx, zaxis=axx,
114+
aspectmode='auto'),
115+
scene4 = list(domain=list(x=c(0.5,1),y=c(0,0.5)),
116+
xaxis=axx, yaxis=axx, zaxis=axx,
117+
aspectmode='manual',
118+
119+
# set your manual fixed aspect ratio
120+
aspectratio = list(x=1, y=1, z=2)))
121+
122+
# Create a shareable link to your chart
123+
# Set up API credentials: https://plot.ly/r/getting-started
124+
chart_link = api_create(p, filename="axes3d-range")
125+
chart_link
126+
```
127+
128+
```{r, echo=FALSE}
129+
chart_link
130+
```
131+
75132
### Set Axes Title
76133

77134
```{r, results = 'hide'}

_posts/r/layout/2017-01-04-3d-axes.md

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ packageVersion('plotly')
3333
```
3434

3535
```
36-
## [1] '4.5.6.9000'
36+
## [1] '4.8.0.9000'
3737
```
3838

3939
### Range of Axes
@@ -70,7 +70,63 @@ chart_link = api_create(p, filename="axes3d-range")
7070
chart_link
7171
```
7272

73-
<iframe src="https://plot.ly/~RPlotBot/3980.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
73+
<iframe src="https://plot.ly/~RPlotBot/5529.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
74+
75+
### Fixed Ratio Axes
76+
77+
78+
```r
79+
library(plotly)
80+
81+
# custom grid style
82+
axx <- list(
83+
gridcolor='rgb(255, 255, 255)',
84+
zerolinecolor='rgb(255, 255, 255)',
85+
showbackground=TRUE,
86+
backgroundcolor='rgb(230, 230,230)'
87+
)
88+
89+
# individual plots
90+
p1 <- plot_ly(z = ~volcano, scene='scene1') %>%
91+
add_surface(showscale=FALSE)
92+
93+
p2 <- plot_ly(z = ~volcano, scene='scene2') %>%
94+
add_surface(showscale=FALSE)
95+
96+
p3 <- plot_ly(z = ~volcano, scene='scene3') %>%
97+
add_surface(showscale=FALSE)
98+
99+
p4 <- plot_ly(z = ~volcano, scene='scene4') %>%
100+
add_surface(showscale=FALSE)
101+
102+
# subplot and define scene
103+
p <- subplot(p1, p2, p3, p4) %>%
104+
layout(title = "3D Subplots",
105+
scene = list(domain=list(x=c(0,0.5),y=c(0.5,1)),
106+
xaxis=axx, yaxis=axx, zaxis=axx,
107+
108+
# select the type of aspectmode
109+
aspectmode='cube'),
110+
scene2 = list(domain=list(x=c(0.5,1),y=c(0.5,1)),
111+
xaxis=axx, yaxis=axx, zaxis=axx,
112+
aspectmode='data'),
113+
scene3 = list(domain=list(x=c(0,0.5),y=c(0,0.5)),
114+
xaxis=axx, yaxis=axx, zaxis=axx,
115+
aspectmode='auto'),
116+
scene4 = list(domain=list(x=c(0.5,1),y=c(0,0.5)),
117+
xaxis=axx, yaxis=axx, zaxis=axx,
118+
aspectmode='manual',
119+
120+
# set your manual fixed aspect ratio
121+
aspectratio = list(x=1, y=1, z=2)))
122+
123+
# Create a shareable link to your chart
124+
# Set up API credentials: https://plot.ly/r/getting-started
125+
chart_link = api_create(p, filename="axes3d-range")
126+
chart_link
127+
```
128+
129+
<iframe src="https://plot.ly/~RPlotBot/5529.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
74130

75131
### Set Axes Title
76132

@@ -103,7 +159,7 @@ chart_link = api_create(p, filename="axes3d-title")
103159
chart_link
104160
```
105161

106-
<iframe src="https://plot.ly/~RPlotBot/3982.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
162+
<iframe src="https://plot.ly/~RPlotBot/5531.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
107163

108164
### Ticks Formatting
109165

@@ -141,7 +197,7 @@ chart_link = api_create(p, filename="axes3d-ticks")
141197
chart_link
142198
```
143199

144-
<iframe src="https://plot.ly/~RPlotBot/3984.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
200+
<iframe src="https://plot.ly/~RPlotBot/5533.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
145201

146202
### Background and Grid Color
147203

@@ -183,7 +239,7 @@ chart_link = api_create(p, filename="axes3d-bg-grid")
183239
chart_link
184240
```
185241

186-
<iframe src="https://plot.ly/~RPlotBot/3986.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
242+
<iframe src="https://plot.ly/~RPlotBot/5535.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
187243

188244
#Reference
189245

0 commit comments

Comments
 (0)