R 将平均值添加到绘图中

R 将平均值添加到绘图中,r,ggplot2,plotly,R,Ggplot2,Plotly,我想要类似于我的示例的东西,但是用黑色的点替换线条。可能吗?文件中没有提到这一点 数据和示例: library(plotly) set.seed(1234) plot_ly(x = ~mean(rnorm(50)), y=c(-2,2), type='scatter', mode='lines') %>% add_boxplot(x = ~rnorm(50), inherit = F) %>% layout(yaxis = list(range = c(-2, 2)))

我想要类似于我的示例的东西,但是用黑色的点替换线条。可能吗?文件中没有提到这一点

数据和示例:

library(plotly)

set.seed(1234)
plot_ly(x = ~mean(rnorm(50)), y=c(-2,2), type='scatter', mode='lines') %>% 
  add_boxplot(x = ~rnorm(50), inherit = F) %>% 
  layout(yaxis = list(range = c(-2, 2)))
我希望ggplot2中有类似的内容:


下面呢

library(plotly)
set.seed(1234)
plot_ly(x = ~mean(rnorm(50)), y=c(-2,2), line = list(color = 'black'), type='scatter', mode='lines') %>% 
  add_boxplot(x = ~rnorm(50), inherit = F) %>% 
  layout(yaxis = list(range = c(-2, 2)))

但是,我不知道你用黑色的点替换线是什么意思。你的意思是你想要两个点,具有相同的x值,但在y比例上为-2和+2?如果是,为什么?

您是否尝试过在ggplot中创建所需的图形,然后传递给ggplotly?是的,这是工作,但我想直接使用plotly来完成
library(plotly)
set.seed(1234)
plot_ly(x = ~mean(rnorm(50)), y=c(-2,2), line = list(color = 'black'), type='scatter', mode='lines') %>% 
  add_boxplot(x = ~rnorm(50), inherit = F) %>% 
  layout(yaxis = list(range = c(-2, 2)))