r - 在 R 图的图例中绘制 "arrow"

标签 r plot

我有一个 “曲线”和直立定位 “箭头”在 R 图中( 参见下面的 R 代码 )。

我想知道是否可以显示 实际箭头 《传奇》 而不是 光滑,直线来区分我的箭头和曲线?

这是我的 R 代码:

curve(dnorm(x), -4, 4, lwd = 3)

arrows(2, 0, 2, .3, code = 2, lwd = 3, col = 'red4')

legend("topleft", legend = c("Curve", "Arrow"), lwd = 3, col = c(1, "red4"))

最佳答案

以下是如何在您的图例中放置一个右箭头代替线。您必须使用 par 访问 font = 5得到一个箭头符号。

curve(dnorm(x), -4, 4, lwd = 3)
arrows(2, 0, 2, .3, code = 2, lwd = 3, col = 'red4')
legend("topleft", legend = c("Curve", "Arrow"), pch = c(NA, NA),
       lwd = 3, col = c(1, "red4"),
       lty = c(1, NA)) #normal legend. Do not plot line
par(font = 5) #change font to get arrows
legend("topleft", legend = c(NA, NA), pch = c(NA, 174),
       lwd = 3, col = c(1, "red4"),
       lty = c(1, NA), bty = "n") 
par(font = 1) #back to default

enter image description here

关于r - 在 R 图的图例中绘制 "arrow",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43052670/

相关文章:

r - 使用 qtm tmap 更改图例的语言

r - 由 R 图的小箭头组成的线

matlab - matlab中的动画情节

python - 在 GUI 嵌入图中使用 matplotlib Cursor 小部件

r - 如何有效地将多个 rgl 图连接成一个图?

r - 如何在 R 中使用 gsub 将字符串替换为单个反斜杠?

r - 使用 car::vif 进行多重共线性测试

r - 为什么在 R 中使用 `ann = F` 绘图时 `as.factor` 不起作用?

python - 在每个数据点处带有对齐注释的散点图

r - 将向量拆分为相等值的连续运行