The following code produces a plot with red markers:
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'))
If I try to add a line I get unwanted red markers also:
plot_ly(data, x = ~x, y = ~trace_0, type = 'scatter', mode = 'markers',
marker = list(color='red'))%>%
add_trace(y = ~trace_1, mode = 'lines')
and a complaint from plot_ly:
A marker object has been specified, but markers is not in the mode
Adding markers to the mode...
Could somebody please explain where I'm going wrong here? Thanks.
This will give you what you want:
plot_ly(data, x = ~x) %>%
add_trace(y = ~trace_0, mode = 'markers', marker = list(color='red')) %>%
add_trace(y = ~trace_1, mode = 'lines')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.