R plotly - get bin sizes / breaks - r

given
library(plotly)
plot_ly(data = wind, x = ~r, type = "histogram")
how do I obtain the sizes of bins/breaks from the default algorithm? I checked the plotly object, I couldn't find the info. It is probably rendered on the JS side?
The output should be in sense of
hist(wind)$breaks

Related

Categorical axes in plotly heatmapgl

Hi I've some problems with heatmapgl plot (but with heatmap I get the same) of plotly package.
I've a distance matrix between a series of elements. I would like to plot a heatmap with names of elements on axes and possibly also on hover text labels.
library(plotly)
values=c(22.63409, 323.93780, 366.31498, 467.94524, 461.93251, 643.61306, 665.03471, 482.49047, 500.06208, 662.71600, 673.29995, 567.99427, 558.41419, 632.86704, 615.55000, 508.01659, 462.50232, 411.39160, 399.00598, 286.55681, 268.69871)
z_matrix=matrix(NA,7,7)
z_matrix[lower.tri(z_matrix, diag=FALSE)] <- values
elements_names=c("ATHOTPlun04", "ATHOTPlun10", "ATHOTPlun16", "ATHOTPlun22", "ATHOTPmar04", "ATHOTPmar10", "ATHOTPmar16")
q <- plot_ly(
x=elements_names,
y=elements_names,
z = z_matrix, type = "heatmapgl") %>%
layout(title = 'Distances for ATHOTP route')
q
Although this is what I get when I run the code:
I tried also to set axes type to "category" in layout options but nothing seems to change. What am I missing? Thank you!
heatmap-gl is used for images where you have continuous x- and y-axes. Therefore you need to change type to a non-continuous type, e.g. type = "heatmap".
q <- plot_ly( x=elements_names,
y=elements_names,
z = z_matrix, type = "heatmap") %>%
layout(title = 'Distances for ATHOTP route')
q

Specify image name and dimensions for ggplotly "download as png" in mode bar

I would like to be able to specify a filename and dimensions for the ggplotly image that is created when a user selects "download as png" from the mode bar on a plot.
I see that there is a way to do this from a plotly graph as asked here, but would like to have similar control coming from a ggplotly graph, similar to the question asked here.
Using that same code example:
x <- c(1:15)
y <- c(1:15)
xy <- as.data.frame(cbind(x, y))
example <- ggplot(data = xy, aes(x = x, y = y)) + geom_line()
ggplotly(example) %>% config(displaylogo = FALSE,
modeBarButtonsToRemove = c(
'sendDataToCloud',
'autoScale2d',
'resetScale2d',
'hoverClosestCartesian',
'hoverCompareCartesian'
))
Is there another config setting that I could utilize to specify a filename/attributes? The downloadImage setting has filename, width, and height, but I am unsure how to access those when coming from a ggplot. The list of config settings I found did not seem to have anything I could repurpose.
Having the ability to specify filename and dimensions would be extremely helpful so that users of my site could download images with more ease and consistency. Also, the ability to add a timestamp/text information to those downloaded images would be even more stellar.

plotly_POST: the plot appears in R Viewer, but not online

I'm trying to publish the plot online via these two lines of code in R:
library('plotly')
plot_ly(data = sampledata, x = date, y = id, type = 'bar')
plotly_POST(sampledata, filename = "Test", world_readable=TRUE)
It doesn't give me any errors or warnings and says "Success! Created a new plotly here ->"
The plot appears in R Viewer, but if I go to my plotly account (or follow the link), I see a blank graph like this:
Blank plotly bar chart
I previously was able to publish one graph online - but I don't recall changing anything in my code.
Any advice is much appreciated!
You'll have to send the whole figure:
p <- plot_ly(data = sampledata, x = date, y = id, type = 'bar')
plotly_POST(p, filename = "Test", world_readable=TRUE)
For a little more information on plotly_POST you can check out this reference: https://plot.ly/r/file-options/

R How to set tick mark size using a trellis theme in Lattice?

I'm trying to use a trellis theme to set all my graphing parameters to keep my plotting statements short. I can't seem to find the correct trellis parameter access tick mark length (or any scale parameters for that matter).
library(lattice)
x = runif(100)
my.theme = trellis.par.get()
my.theme$axis.line = list(tck=c(4)) # this does not work
dp <- densityplot(~x)
# this works, but I want to do it using a theme
# dp <-densityplot(~x, scales=list(y=list(tck=c(4))))
png("dp.png", width=400, height=200)
trellis.par.set(my.theme)
plot(dp); dev.off()
Tick lengths for each of the plot's axes are controlled by (elements of) axis.components in lattice's graphical parameter list.
Run str(trellis.par.get("axis.components")) to see what you are aiming for, and then do something like the following:
mytheme <- list(axis.components = list(left = list(tck=4), right = list(tck=4)))
trellis.par.set(mytheme)
densityplot(~x)

How to plot all of huge data points in scatter3d of plot_ly?

I have a data.frame named as z, which has 4 millions data points to make scatter3d plot by using plot_ly as follows.
p <- plot_ly(z, x = ~Lon, y = ~Lat, z = ~z,
mode = 'markers',
marker = list(color = "black",size = 2, opacity =0.05),
type = 'scatter3d', source = 'scatter')
htmlwidgets::saveWidget(as_widget(p), "scatter3d_plotly.html") # save as html
Then, I came across an error, saying
pandoc.exe: Out of memory
Error: pandoc document conversion failed with error 251
Because I assumed that this was a problem with memory allocation, I tested if downsampling can help to make a tentative plot as follows;
z_ds <- sample_frac(tbl = z, size = 0.01) # downsampled into 1%
Now, this works, which made sure that this is a problem of memory.
However, downsampling is not appropriate in my research purpose, and what I need is plotting all the 4 million data points in one figure.
In summary,
I want a scatter3d plot with all 4 millions data point
I do not really need completely "interactive" 3D plot if this makes difficult to deal with huge data point
But, hopefully, I want to keep the "3D rotating feature" in the html format by drag.
It does not have to use Plotly if there is alternative.
Would you please give me any suggestion about this?

Resources