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

Not able to get 3D surface subplots using Plotly R #844

Closed
tarunparmar opened this issue Jan 5, 2017 · 2 comments
Closed

Not able to get 3D surface subplots using Plotly R #844

tarunparmar opened this issue Jan 5, 2017 · 2 comments

Comments

@tarunparmar
Copy link

tarunparmar commented Jan 5, 2017

Hi,
I am not able to get all the 3D surface plots in one picture with below code. This same code worked fine with type="box" and "histogram".
The code below only generates one plot, but if you then if you check "plots" variable it does have 3 separate plots.

I found the plotly with Python can do this but there is no R page for this. (https://plot.ly/python/3d-subplots)

Can you suggest if I am doing something wrong here?

df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/3d-line1.csv')
lst <- levels(factor(df$color))
plots <- list()
for(i in 1:nlevels(factor(df$color))){
subdf <- dplyr::filter(df, color == lst[i])
dens = akima::interp(subdf$x, subdf$y, subdf$z, duplicate = "mean")
p <- plot_ly(x = dens$x, y = dens$y, z = dens$z, colors = c("blue","red"), type = "surface)
plots[[i]] <- p
}
subplot(plots, nrows = 2)

image

One another note, I am doing subplots for type="contour" and it makes the plots but the legend seems to get overlapped. Can each subplot have its own legends?

image

For example, with same dataset above, here is what I get...

df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/3d-line1.csv')
lst <- levels(factor(df$color))
plots <- list()
for(i in 1:nlevels(factor(df$color))){
  subdf <- dplyr::filter(df, color == lst[i])
  dens = akima::interp(subdf$x, subdf$y, subdf$z, duplicate = "mean")
  p <- plot_ly(x = dens$x, y = dens$y, z = dens$z, colors = c("blue","red"), type = "contour") #%>% add_surface()
  plots[[i]] <- p
}
subplot(plots, nrows = 2)

image

@cpsievert
Copy link
Collaborator

Duplicate of #711

@tarunparmar
Copy link
Author

tarunparmar commented Jan 5, 2017

@cpsievert
Hi Carson,
Thanks for checking it out .
I found this out today that scene argument can be passed inside plotly object and laos I have to update my Plotly to 4.5.6.9000.

Upgrading did fix the problem. But weird with everything matched to exact version, it works fine on my Mac but doesnt work on my work Windows laptop.

Also on the mac, it seem to only plot all the subplots in one row even with nrows = 2.

Any idea if I am still missing something or if this could be a possible bug.

p1 <- plot_ly(z = ~volcano, scene='scene1') %>% add_surface()
p2 <- plot_ly(z = ~volcano, scene='scene2') %>% add_surface()
p3 <- plot_ly(z = ~volcano, scene='scene3') %>% add_surface()
p4 <- plot_ly(z = ~volcano, scene='scene4') %>% add_surface()
subplot(p1, p2, p3, p4, nrows = 2)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants