Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

3d - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...