在R散点图中更改标记颜色的问题 [英] Issue changing marker color in R plotly scatter plot

查看:902
本文介绍了在R散点图中更改标记颜色的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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')

和plot_ly的投诉:

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')

这篇关于在R散点图中更改标记颜色的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆