Ich versuche, eine 3d-Linie zu einem 3D plot_ly Oberflächendiagramm hinzuzufügen. Wenn ich die Funktion add_lines() nicht innerhalb von plot_ly hinzufüge, sieht es gut aus. Sobald ich die add_lines hinzufüge, wird der Graph komplett durcheinander gebracht und das 3D-Liniendiagramm wird nicht hinzugefügt. Ich benutze plotly 4.7.0.R: Plot_ly 3D-Grafik mit Spurlinie
library(plotly)
m_x = seq(-2, 2, .01)
m_y = seq(-2, 2, .01)
df = expand.grid(m_x, m_y)
df['matrix'] = exp(-(df$Var1^2+df$Var2^2))
m_z = matrix(df$matrix, nrow = length(m_x), ncol = length(m_y))
m_df = list(m_x, m_y, m_z)
x1 = seq(-2, 0, by=0.0202)
y1 = runif(100, min=-0.03,max=0.03)
z1 = exp(-(x1^2+y1^2))
df = data.frame(x1, y2, z2)
names(df) <- c("df_x", "df_y", "df_z")
colors = c("Blue", "Cyan", "Green", "Yellow", "Orange", "Red")
p1 <- plot_ly(x = m_df[[1]], y = m_df[[2]], z = m_df[[3]],
colors = colors, color = m_df[[3]]) %>% add_surface() %>%
add_lines(x = df$df_x, y = df$df_y, z = df$df_z, data = df,
line = list(color = 'red', width = 1)) %>%
layout(title = "Hike_Example",
scene = list(aspectratio = list(x = 4, y = 4, z = 1)))
p1
In 'data.frame (x1, y2, z2)' 'Objekte y2' und' z2' nicht –