R 使用plotly将点添加到现有散点图

R 使用plotly将点添加到现有散点图,r,plot,plotly,R,Plot,Plotly,假设我有以下数据帧: a <- c(1,2,2,3,7,9,8,3,7,9) b <- c(1:10) df1 <- data.frame(a,b) c <- c(2,5,4) d <- c(3,6,5) df2 <- data.frame(c,d) a您可以尝试: colnames(df2) <- c("a", "b") df1$gr <- 1 df2$gr <- 2 df <- rbind(df1, df2) plot_ly(da

假设我有以下数据帧:

a <- c(1,2,2,3,7,9,8,3,7,9)
b <- c(1:10)
df1 <- data.frame(a,b)
c <- c(2,5,4)
d <- c(3,6,5)
df2 <- data.frame(c,d)
a您可以尝试:

colnames(df2) <- c("a", "b")
df1$gr <- 1
df2$gr <- 2
df <- rbind(df1, df2)
plot_ly(data = df, x = ~a, y = ~b, color = ~factor(gr), type = "scatter")

colnames(df2)查看plotly教程,我看不到向网页上的上一个绘图添加点的其他方法。事实上,我在普罗特利的官方文件中找不到相关的东西。
colnames(df2) <- c("a", "b")
df1$gr <- 1
df2$gr <- 2
df <- rbind(df1, df2)
plot_ly(data = df, x = ~a, y = ~b, color = ~factor(gr), type = "scatter")