问题:更改R plotly散点图中的标记颜色

问题:更改R plotly散点图中的标记颜色,r,plotly,R,Plotly,以下代码生成带有红色标记的绘图: trace_0 <- rnorm(100, mean = 5) trace_1 <- rnorm(100, mean = 0) x <- c(1:100) data <- data.frame(x, trace_0, trace_1) plot_ly(data, x = ~x, y = ~trace_0, type = 'scatter', mode = 'markers', marker = list(color='

以下代码生成带有红色标记的绘图:

trace_0 <- rnorm(100, mean = 5)
trace_1 <- rnorm(100, mean = 0)
x <- c(1:100)

data <- data.frame(x, trace_0, trace_1)

plot_ly(data, x = ~x, y = ~trace_0, type = 'scatter', mode = 'markers',
        marker = list(color='red'))

以及plot_y的投诉:

A marker object has been specified, but markers is not in the mode
Adding markers to the mode...

有人能解释一下我哪里出了问题吗?谢谢。

这将为您提供您想要的:

plot_ly(data, x = ~x) %>%
add_trace(y = ~trace_0, mode = 'markers', marker = list(color='red')) %>%
  add_trace(y = ~trace_1, mode = 'lines')
plot_ly(data, x = ~x) %>%
add_trace(y = ~trace_0, mode = 'markers', marker = list(color='red')) %>%
  add_trace(y = ~trace_1, mode = 'lines')