DEFNE SELEN AKDEMİR
DEFNE SELEN AKDEMİR

Reputation: 31

Argument is missing while trying to add surface (R)

I am trying to run these functions to establish a 3D plot and I want to add a plane but an error occurs.

plot_ly(data = df, z = ~PM, x = ~Wind_speed, y = ~SO2, opacity = 0.5) %>%
  add_markers()
x <- seq(370, 15000, by = 10)
y <- seq(0, 15000, by = 10)
plane <- outer(x, y, function(a, b){fit$coef[1] + 
    fit$coef[2]*a + fit$coef[3]*b})
add_surface(x = ~x, y = ~y, z = ~plane, showscale = FALSE)

but then this error shows up

> add_surface(x = ~x, y = ~y, z = ~plane, showscale = FALSE)
Error in add_trace_classed(p, class = "plotly_surface", z = z, type = "surface",  : 
  argument "p" is missing, with no default

What should I do to fix this?

Upvotes: 1

Views: 94

Answers (1)

DEFNE SELEN AKDEMİR
DEFNE SELEN AKDEMİR

Reputation: 31

I do not know how it got solved but I could fix it somehow. I just reloaded the data, changed the order of the functions and wrote these functions together:

x <- seq(370, 15000, by = 10)
y <- seq(0, 15000, by = 10)
plane <- outer(x, y, function(a, b){fit$coef[1] + 
    fit$coef[2]*a + fit$coef[3]*b})
plot_ly(data = df, z = ~PM, x = ~Wind_speed, y = ~SO2, opacity = 0.5) %>%
  add_markers()
add_surface(x = ~x, y = ~y, z = ~plane, showscale = FALSE)

Upvotes: 1

Related Questions