hafen / trelliscopejs

TrelliscopeJS R Package
https://hafen.github.io/trelliscopejs
Other
263 stars 36 forks source link

3D plotting in Trelliscope #80

Open TaylorBale opened 5 years ago

TaylorBale commented 5 years ago

I am attempting to plot a 3D plotly scatterplot in Trelliscope and have received various errors. One of which is, "the list does not contain 2 elements", and the other I have come across most recently is, "panel not written - must be trellis, ggplot, or htmlwidget object." From these errors, I am gathering that Trelliscope does not support 3D plotly images, is this correct? If my assumption is correct, does Trelliscope support any interactive 3D plotting options? I have attached an image of my test code for review. 3D_Trelliscope

hafen commented 5 years ago

Interesting. I'm not sure what it might be about 3d that would be making it not work. Could you copy and paste the code in your screenshot as a reply to this comment? Then I'll look into it further.

TaylorBale commented 5 years ago
library(tidyverse)
library(trelliscopejs)
library(plotly)
library(rbokeh)

# Creating the df
x <- c(1, 2, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1.5)
y <- c(1, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 2.5)
z <- c(1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 3)
class <- c("a", "a", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b", "b")
df <- data.frame(x,y,z, class)
# Test plot
plot_ly(df, x = ~x, y = ~y, z = ~z, color = ~as.factor(class))

# Using plotly 3D --------------------------------------------------------------
df_tr2 <- df %>%
  group_by(class) %>%
  nest() %>%
  mutate(
    panel = map_plot(data, ~ figure(xlab = "X", ylab = "Y", zlab = "Z") %>%
                      ~ plot_ly(.x, x = ~x, y = ~y, z = ~z)))

df_tr2 %>%
  trelliscope("junk1", nrow = 1, ncol = 3)

# How about 2D using plotly function?
df_tr2 <- df %>%
  group_by(class) %>%
  nest() %>%
  mutate(
    panel = map_plot(data, ~ figure(xlab = "X", ylab = "Y") %>%
                       ~ plot_ly(.x, x = ~x, y = ~y)))

df_tr2 %>%
  trelliscope("junk1", nrow = 1, ncol = 3)

# Looks like it is plotting all the points, but not in 3D
df_tr <- df %>%
  group_by(class) %>%
  nest() %>%
  mutate(
    panel = map_plot(data, ~ figure(xlab = "X", ylab = "Y", zlab = "Z") %>%
                       ly_points(x, y, z, data = .x)))

df_tr %>%
  trelliscope("junk1", nrow = 1, ncol = 3)

Created on 2019-06-27 by the reprex package (v0.3.0)