Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Higher resolution / programmatic 3D plots #330

Closed
trevorcampbell opened this issue Oct 9, 2021 · 5 comments
Closed

Higher resolution / programmatic 3D plots #330

trevorcampbell opened this issue Oct 9, 2021 · 5 comments
Labels
low priority nice but not important or mandatory v1 must fix must be addressed before v1.0

Comments

@trevorcampbell
Copy link
Contributor

trevorcampbell commented Oct 9, 2021

From @ttimbers : I CANNOT programmatically save a nice, high resolution view of a 3D plotly scatter plot. Current one in PDF is a screen shot. This might be helpful: https://stackoverflow.com/questions/63460719/plotly-how-to-set-manual-zoom-for-camera-view-in-a-3d-plot. If we can figure that out, we need to add orca to the Dockerfile so that we can save plotly plots to .png for PDF version.

@trevorcampbell trevorcampbell added the v1 must fix must be addressed before v1.0 label Oct 9, 2021
@trevorcampbell trevorcampbell mentioned this issue Oct 9, 2021
2 tasks
@ttimbers
Copy link
Contributor

ttimbers commented Oct 20, 2021

This will change the plot3d object in classification1.Rmd camera angle to be nice:

scene = list(camera = list(eye = list(x=2, y=2, z = 1.5)))
plot_3d <- plot_3d  |> 
  layout(title = "changed zoom", scene = scene)

and then we can programmatically save it to a svg via:

orca(plot_3d, "3d-knn-classification.svg")

However, to do this we need to install orca and the processx R package... I figured out how to do this on my mac, will try for the container now...

@ttimbers
Copy link
Contributor

OK, orca is depracted, we use reticulate + the python-kaleido package.

Install via:

install.packages('reticulate')
reticulate::install_miniconda()
reticulate::conda_install('r-reticulate', 'python-kaleido')
reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')
reticulate::use_miniconda('r-reticulate')

Then use this R code:

save_image(plot_3d, "img/3d-knn-classification.svg")

ttimbers added a commit that referenced this issue Oct 20, 2021
This allows saving plotly images as documented in #330
@ttimbers
Copy link
Contributor

So I think this code will do it:

# add this in setup chunk
reticulate::use_miniconda('r-reticulate')

# use this control flow in plot chunk to conditionally save 
# high resolution image if plotting in LaTeX and then load it 
if(!is_latex_output()){  
  plot_3d
} else {
  scene = list(camera = list(eye = list(x=2, y=2, z = 1.5)))
  plot_3d <- plot_3d  %>% layout(scene = scene)
  save_image(plot_3d, "img/test.png", scale = 10)
  knitr::include_graphics("img/plot3d_knn_classification.png")
}

@ttimbers
Copy link
Contributor

ttimbers commented Oct 20, 2021

Here's what it looks like now:

Screen Shot 2021-10-19 at 9 55 15 PM

@ttimbers
Copy link
Contributor

This is resolved for the regression plots sufficiently, however the marker size is too large via the method I am using for the plot in classification1.Rmd. So my workaround for now is a screenshot. Leaving this open until we fully resolve it...

@ttimbers ttimbers added help wanted Extra attention is needed low priority nice but not important or mandatory and removed help wanted Extra attention is needed labels Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority nice but not important or mandatory v1 must fix must be addressed before v1.0
Projects
None yet
Development

No branches or pull requests

2 participants