r - 仅更改 R 中线段的粗细而不更改长度

标签 r plot

我想知道如何增加线段的厚度(应该从-2到2)在我的 R 图中不增加长度? (请参阅下面我的 R 代码)

注意:显然,lwd 除了厚度之外,还会按比例增加长度线段。 例如,在下图中,即使线段设置为从 -2 到 2,但红色线段的长度却超出了 -2 和 2。

enter image description here

这是我的 R 代码:

curve(dnorm(x), -4, 4, lwd = 3)
segments(-2, 0, 2, 0, col = 'red', lend = 2, lwd = 20)

最佳答案

你想要lend = 1lend =“butt”

curve(dnorm(x), -4, 4, lwd = 3)
segments(-2, 0, 2, 0, col = 'red', lwd = 20, lend = "butt")

以及使用多边形的解决方法

curve(dnorm(x), -4, 4, lwd = 3)
polygon(x = c(-2,2,2,-2), y = c(0,0,0.02,0.02), col = "red", border = NA)

关于r - 仅更改 R 中线段的粗细而不更改长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43083387/

相关文章:

html - 如何使用 Google 电子表格作为后端创建 HTML 数据输入表单

R包开发: run_examples Error: Can't find directory

r - 如何使用序列频率将第二个 y 轴添加到 seqfplot?

r - 为什么在将点传递给 purrr 中的映射函数时需要引用或取消引用点?

r - Autoplot 仅使用 R 中的时间序列寓言绘制 ETS 的预测

python - 没有 fillcolor 无法在 python 中绘制椭圆

python - 绘制两个 Pandas 系列后在 matplotlib 中创建图例

matlab - 同时将 matlab 图形中的多条线条颜色设置为不同的值

python - 每当 matplotlib 中两条线相遇时,如何使用 Python 打印某些内容?

r - 计算 Xts 列的滚动排名