简体   繁体   English

如何在 R 的条形图中添加线段?

[英]How do you add a line segment to a stripchart in R?

This is likely a very easy question, but I'm not great with R and haven't found a simple answer elsewhere on the internet.这可能是一个非常简单的问题,但我对 R 不太满意,并且在互联网上的其他地方也没有找到简单的答案。

I want to add a line segment connecting the two points in this stripchart, but cannot figure out how to do so.我想在这个带状图中添加一条连接两点的线段,但不知道该怎么做。

stripchart(c(0.5, 1.5), pch = "+")

Any help would be much appreciated!任何帮助将非常感激!

Create a data frame or vectors with the coordinates for the line and plot with lines使用线的坐标创建数据框或向量,并使用lines创建 plot

df1 <- data.frame(x = c(0.5, 1.5),
                  y = 1)

stripchart(c(0.5, 1.5), pch = "+")
lines(df1$x, df1$y)

Created on 2021-12-18 by the reprex package (v2.0.1)reprex package (v2.0.1) 于 2021 年 12 月 18 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM