- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想向 plotly
添加一条线(不仅仅是垂直或水平)图表
library(plotly)
d = data.frame(x=1:10, y=1:10)
plot_ly(d, x = ~x, y = ~y, type='scatter')
(D) y = 2x
作为一条线,我可以在不自己生成数据的情况下在
d
的另一列中进行绘图
最佳答案
至少有两种模拟方式 abline
.
line
形状到layout
带有起点和终点 min
和
max
需要计算每个跟踪(
Plotly
无论如何都需要这样做,但它会使代码膨胀)。
xaxis
和
yaxis
range
手动。
shape
添加的。
line
.
library('plotly')
#a function to calculate your abline
p_abline <- function(x, a=2, b=-5){
y <- a * x + b
return(y)
}
#create an empty plot
p <- plot_ly()
#list with all your x and y values
x <- list(c(1,2,3), c(2,3,6), (1:5))
y <- list(c(1,2,3), c(0,5,10), sample(-10:10, 5))
#loop through the x/y values and determine min/max
for (i in 1:length(x)) {
p<-add_trace(p, y=y[[i]], x=x[[i]] , type="scatter", mode="markers+lines")
if (i == 1 || max(x[[i]]) > max_x) {
max_x = max(x[[i]])
}
if (i == 1 || max(y[[i]]) > max_y) {
max_y = max(y[[i]])
}
if (i == 1 || min(x[[i]]) < min_x) {
min_x = min(x[[i]])
}
if (i == 1 || min(y[[i]]) < min_y) {
min_y = min(y[[i]])
}
}
#add a trace to simulate abline
p<-add_trace(p, x=c(min_x, max_x), y=c(p_abline(min_x), p_abline(max_x)) , type="scatter", mode="lines", name='abline')
#add a shape (line) to simulate abline
p <- p %>% layout(
shapes=list(type='line', x0=min_x, x1=max_x, y0=p_abline(min_x, -1, 3), y1=p_abline(max_x, -1, 3))
)
p
关于r - 相当于 abline 在 plotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41980772/
我正在处理一个 R 图,该图将被我用 abline() 创建的垂直线分成两部分.我希望那个abline只在一侧越过我的情节边界。 我找到了 this关于设置的有用帖子 par(xpd=) .但是,我无
我在 R 中有一个数据,所以我想测试各种模型上的数据。我将数据分成两组,80% 的训练和 20% 的测试。所以现在我想做的是在线性模型上训练训练数据集,并在测试数据集上进行预测。 到目前为止,我已经这
> head(returnee) [1] 1.3936536 -0.6730667 2.3584725 2.3477308 3.2841443 1.3168157 > head(vixee)
对 R(老实说是统计学)还是很陌生,我目前只将它用于简单的线性回归模型。但现在我的一组数据清楚地显示了倒 U 型。我想我必须对这些数据进行二次回归分析,但我不确定如何做。到目前为止我尝试的是:
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭10
我想在 fx 上放置一个文本字符串。 abline(0,0.2) 但是在我的 for 循环中,数据的比例(fx. 0,01-1 和 5-2000)正在发生变化,那么如何控制文本的位置,使其始终很好地位
我想在我的水平图上绘制水平线和垂直线,对应于从 74 到 76 的 x 值和从 28 到 32 的 y 值。下面是我的 R 代码。但是当我运行以下命令时,我得到了水平图但没有线条。我也没有收到来自 R
我想在我的水平图上绘制水平线和垂直线,对应于从 74 到 76 的 x 值和从 28 到 32 的 y 值。下面是我的 R 代码。但是当我运行以下命令时,我得到了水平图但没有线条。我也没有收到来自 R
我画了一个等高线图并添加了一条对角线: library(MASS) library(fields) x <- c(21.06, 28.89, 23.00, 23.61, 23.61, 22.83, 3
我有一个“长”数据框定义为: q <- data.frame(Indicator.Code=factor(),Year=numeric(),Value=numeric()) 并且我试图在单个 xypl
我想向 plotly 添加一条线(不仅仅是垂直或水平)图表 library(plotly) d = data.frame(x=1:10, y=1:10) plot_ly(d, x = ~x, y =
以下代码显示了 abline 的异常行为:绘制的线没有达到指定的截距。我使用的是 Rstudio 版本 0.98.976。有什么提示可以避免这个问题吗? x=seq(1,10) y=seq(1,10)
对于 3D 散点图,是否有替代“abline”的方法?我正在使用“scatterplot3d”包。 图中的蓝线是我想要做的。如果我添加一个“表面”,那么它将阻塞原始图。 最佳答案 是这样的吗? th
我正在尝试使用 abline(lm(...)) 绘制最小二乘回归线这也被迫通过一个特定的点。我看到this question是相关的,但不是我想要的。下面是一个例子: test <- structur
我在 R 中运行了回归,当试图将 abline 拟合到绘图时,没有任何反应,也没有出现错误消息。 我不得不对数据进行日志转换,所以我想知道这是否是问题所在?数据不是正态分布的,但我们仍然被要求执行回归
我正在尝试在我的 ggplot 上绘制 abline。 我可以使用以下方法绘制数据: modl %>% ggplot() + geom_line(aes(x = date, y = logPr
我在使用 abline() 时一直无法解决错误。我不断收到警告消息:在 abline(model): 只使用 7 个回归系数中的前两个。我一直在搜索并看到许多其他有此错误的实例,但它们的示例适用于多个
我正在尝试截断 abline 的末端,这实际上只是我数据的线性回归。 fit1=lm(logy~logx) > fit1 Call: lm(formula = logy ~ logx) Coeffic
我无法在图表中添加垂直线或水平线。我觉得我错过了一些非常简单的东西,但我似乎找不到它。我已经从互联网上复制了一些示例,但它不起作用。我做错了什么? 这就是我正在尝试的: library(quantmo
我可以毫无问题地做到这一点: boxplot(coef ~ habitat, data = res) abline(h = 0, col = "green") 但是当我使用 lattice 时,水平线
我是一名优秀的程序员,十分优秀!