3d scatter animation in R, plotly - r

I have a 3D plot in plotly for R that I want to put into a presentation. Is there a way I can animate the 3D space rotating in some way as a .gif or other from R?
I understand how to make the plot, how to rotate it on my own, and how to publish it on RPubs, but can't figure out how to save it out. Example below.
# build dataframe
df <- data.frame(replicate(3,sample(0:25,50,rep=TRUE)))
# 3d scatterplot
p1 <- plot_ly(df, x = ~X1, y = ~X2, z = ~X3,
type = "scatter3d",
mode = "markers")
p1
Now we have a cool 3D scatterplot in viewer that user can rotate with mouse drags, but I want to save it out to rotate on its own. There is also a 'save to png' button in the viewer, but when I click it, a text box pops up that says "there was a problem saving your image." I'm thinking some kind of loop that saves images out at different viewer angles, then stitches them together? Any ideas appreciated.
I also tried using the orca() command and received the following error:
orca(p1,file="3dplot.png")
Error: The orca command-line utility is required for this functionality.
Not sure what it means.

In the Viewer tab, if you click Export and Save as Web Page... you might get what you want. Remember to use the .html extention
Neither of both options Save to png or orca() are going to work because the save a snapshot of the current angle so you lose the dynamic part.
Best!

Related

Highlight values and save

I am using plotly to zoom my plots, save to svg and show most interesting intervals to customers. The thing I can't reach - I need to save picture with hover showing values.
For example, I zoomed, I pointed value I need to show, I see values using hover.
But when I press "Download plot" button - It's saved without hover information. Here is what I see in svg:
How can I show values on saved plots?
Here is my example code:
library(plotly)
x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)
fig <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')
fig
I really don't know any thing about the software/code you are using but as a general logic you have some different approaches to solve this.
1-create a function to take a screenshot of the area you have on screen with those hovering elements and save it as a bitmap image. This is valid just if you don't require to save/download your plot as an svg file.
2- In case you need to export as svg then you have to create a function to observe and get the svg code which is displaying your plot at the moment of hovering, then save the whole stuff as svg file.
3-If what you require is to save the plot as a svg file then it is also possible that the hovering effect along with the code to produce the highlighted content, to be exported inside the svg. The only means most users have t visualize an svg file is via web browser, so when the parts conteining hovering are hovered they will show the effect and the information.
As I said, these are just general logic to try to find out a solution.

How do I retrieve camera parameters from a plotly.js 3D plot?

I plot 3D scenes from Julia using PlotlyJS into an Electron window. When I change the viewing parameters with the mouse, zooming, panning, or rotating, how do I get the eye, center, and the up vector from the plot? Even when I save the plot into a JSON file, the camera parameters are those of the original plot.
I found that setting the options of the plot as
options=Dict(:showLink => true)
equips the plot with a link to a web site where the plot can be manipulated. The camera settings can be read off there. See, for instance, https://github.com/PetrKryslUCSD/FinEtoolsFlexBeams.jl/blob/master/examples/graphics/edit_plot.jl

Save viewer object rendered in RStudio as image

I created an object that is viewed in the RStudio viewer, such as chart in plotly or highcharter or a map in leaflet. I would like to save that object as a png. There are a number of ways to do this. For example, there's this method that uses webshot. It's possible to use orca. There are several methods. The problem with all of these is that the output image is slightly different than the version seen in the viewer. This is a problem for me because I need both the interactive version of the chart as well as a static version and I don't want to have to create two versions and write all the code associated with producing both to make sure each one comes out just as I need.
However, RStudio has a built-in method that can be accessed by clicking "Export -> Save as Image" in the viewer pane. I would like to use this method because it preserves the layout exactly as seen in the viewer.
I tried using R's built-in plot saving method of png, plot and devoff, but that appears to only work for plot objects, not viewer objects.
There has to be a way to reproduce the physical steps of saving as an image in RStudio programmatically, right? Doing it manually would be really time-consuming.
Here's an sample chart in plotly that shows up in the viewer.
plot_ly(z = ~volcano, type = "surface")

Is there a way to save and quickly reopen surface plots in IDL (Interactive Data Language)?

I was wondering if there is a way to save surface plots in IDL in a way that is convenient to reopen them. As far as I am aware there are only two ways of doing this:
The first way is to save your surface plot as an image e.g. png. The trouble with this is that the viewing angle is fixed and you can no longer drag with the mouse to rotate the surface plot.
The second way is to save the code which generates the plot. Trouble with this is the code often generates loads of plots which are usually just saved as images.
I would like something you can open easily and which opens the surface plot as though you had just run the code to generate it. So that you are free to rotate it by dragging the mouse.
Does this exist?
I only have IDL version 8.3.
If you 'Generate code/save data' (either via the toolbar at the bottom of the window or via the generateCode method with the SAVEDATA keyword), you get a .sav file that contains your plot. Either use the code generated to restore it, or use the generated code as an example to write your own.

Get data from mouse events in plot.ly or ggvis within r (not shiny)

I want to use interactive plots in R to be able to select x intervals in plots, i have tried plot.ly and ggvis and it seems that the mouse click on the plot followed by horizontal drag, used for zooming is exactly what i want, but zoom would have to be disabled and the [x start, x end] values must be returned to R. Any ideas if this is possible, and if so, how?
I tried to make tooltip function available with static_output (without shiny).
You can check my fork (https://github.com/lujiacn/ggvis
), enable the tooltip by default, in Rstudio and output html widget.
The way is put tooltip content in one variable called "tooltip". If no "tooltip" variable, wills show the all values linked to the data.

Resources