Skip to content

Commit 0622fa0

Browse files
committed
improved resolution and automation of 3D plotly figures in pdf
Closes #330
1 parent efc4fbe commit 0622fa0

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

build_html.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Script to generate HTML book
2-
docker run --rm -m 5g -v $(pwd):/home/rstudio/introduction-to-datascience ubcdsci/intro-to-ds:v0.15.0 /bin/bash -c "cd /home/rstudio/introduction-to-datascience; Rscript _build_html.r"
2+
docker run --rm -m 5g -v $(pwd):/home/rstudio/introduction-to-datascience ubcdsci/intro-to-ds:v0.16.0 /bin/bash -c "cd /home/rstudio/introduction-to-datascience; Rscript _build_html.r"

build_pdf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cp -r data/ pdf/data
2222
cp -r img/ pdf/img
2323

2424
# Build the book with bookdown
25-
docker run --rm -m 5g -v $(pwd):/home/rstudio/introduction-to-datascience ubcdsci/intro-to-ds:v0.15.0 /bin/bash -c "cd /home/rstudio/introduction-to-datascience/pdf; Rscript _build_pdf.r"
25+
docker run --rm -m 5g -v $(pwd):/home/rstudio/introduction-to-datascience ubcdsci/intro-to-ds:v0.16.0 /bin/bash -c "cd /home/rstudio/introduction-to-datascience/pdf; Rscript _build_pdf.r"
2626

2727
# clean files in pdf dir
2828
rm -rf pdf/references.bib

classification1.Rmd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ knitr::opts_chunk$set(echo = TRUE,
1010
options(knitr.table.format = function() {
1111
if (knitr::is_latex_output()) 'latex' else 'pandoc'
1212
})
13+
reticulate::use_miniconda('r-reticulate')
1314
```
1415

1516
## Overview
@@ -598,7 +599,7 @@ plot_3d <- scaled_cancer_3 |>
598599
z = ~Symmetry,
599600
color = ~Class,
600601
opacity = 0.4,
601-
size = 150,
602+
size = 5,
602603
colors = c("orange2", "steelblue2", "red"),
603604
symbol = ~Class, symbols = c('circle','circle','diamond'))
604605
@@ -637,6 +638,9 @@ plot_3d <- plot_3d %>%
637638
if(!is_latex_output()){
638639
plot_3d
639640
} else {
641+
scene = list(camera = list(eye = list(x=2, y=2, z = 1.5)))
642+
plot_3d <- plot_3d %>% layout(scene = scene)
643+
save_image(plot_3d, "img/plot3d_knn_classification.png", scale = 10)
640644
knitr::include_graphics("img/plot3d_knn_classification.png")
641645
}
642646
```

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
book-env:
3-
image: ubcdsci/intro-to-ds:v0.12.0
3+
image: ubcdsci/intro-to-ds:v0.16.0
44
ports:
55
- "8787:8787"
66
volumes:
@@ -10,5 +10,5 @@ services:
1010
deploy:
1111
resources:
1212
limits:
13-
memory: 4G
13+
memory: 5G
1414

regression1.Rmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ library(knitr)
55
library(plotly)
66
77
knitr::opts_chunk$set(fig.align = "center")
8+
reticulate::use_miniconda('r-reticulate')
89
```
910

1011
## Overview
@@ -797,6 +798,9 @@ plot_3d <- plot_ly() |>
797798
if(!is_latex_output()){
798799
plot_3d
799800
} else {
801+
scene = list(camera = list(eye = list(x=2, y=2, z = 1.5)))
802+
plot_3d <- plot_3d %>% layout(scene = scene)
803+
save_image(plot_3d, "img/plot3d_knn_regression.png", scale = 10)
800804
knitr::include_graphics("img/plot3d_knn_regression.png")
801805
}
802806
```

regression2.Rmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ library(knitr)
55
library(plotly)
66
77
knitr::opts_chunk$set(fig.align = "center")
8+
reticulate::use_miniconda('r-reticulate')
89
```
910

1011
## Overview
@@ -491,6 +492,9 @@ plot_3d <- plot_ly() |>
491492
if(!is_latex_output()){
492493
plot_3d
493494
} else {
495+
scene = list(camera = list(eye = list(x=2, y=2, z = 1.5)))
496+
plot_3d <- plot_3d %>% layout(scene = scene)
497+
save_image(plot_3d, "img/plot3d_linear_regression.png", scale = 10)
494498
knitr::include_graphics("img/plot3d_linear_regression.png")
495499
}
496500
```

0 commit comments

Comments
 (0)