![](/img/trans.png)
[英]Dropdown menu for changing the color attribute of data in scatter plot (Plotly R)
[英]Issue changing marker color in R plotly scatter plot
以下代碼生成帶有紅色標記的圖:
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_ly(data, x = ~x, y = ~trace_0, type = 'scatter', mode = 'markers',
marker = list(color='red'))%>%
add_trace(y = ~trace_1, mode = 'lines')
以及plot_ly的投訴:
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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.