标签: r plotly
我有一个类似下面的直方图,我想在直方图的顶部绘制一个特定值的垂直线。
我的直方图代码是:
library(plotly) p <- plot_ly(x = ~rnorm(50,mean = 50,sd = 10), type = "histogram") p
我想在直方图上叠加一条线,例如,
x <- 42
有人可以帮忙搞定吗?
答案 0 :(得分:2)
library(plotly) set.seed(1) p <- plot_ly(x = ~rnorm(50,mean = 50,sd = 10), type = "histogram") %>% add_segments(x=42, y=0, xend=42, yend=14, line=list(color="red", width = 4)) p