r - 在R中制作方轴

标签 r graphics plot

如何使用 R 使轴在散点图中始终为正方形?例如在:

> plot(iris)

或者
> plot(iris$Petal.Width, iris$Petal.Length)

我希望轴是方形的,即 x 和 y 轴的长度和刻度标签相同。

当前建议的答案不起作用:电话,
plot(iris$Petal.Width, iris$Petal.Length, xlim=c(0,10), ylim=c(0,10), asp=1)

生成:

enter image description here

它不是方形的,并且没有相同的轴刻度和刻度标签。 x 刻度标签之间的间距必须相同,并且绘图应该是正方形,而不是矩形。

最佳答案

您还需要设置 pty="s"在图形参数中使绘图区域为正方形(与设备大小和限制无关):

par(pty="s")
plot(iris$Petal.Width, iris$Petal.Length, asp=1)
lines(2+c(0,1,1,0,0),3+c(0,0,1,1,0)) # confirm square visually

tall long

关于r - 在R中制作方轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14656398/

相关文章:

r - 使用 ape 包在 R 中进行标签和色叶树状图(系统发育)

通过另一个向量中包含的字符串动态引用向量名称

r - 使用 R ggplot 绘制宽格式数据

r - 无法将 tidyselect `everything()` 与 `group_by()` 和 `fill()` 结合使用

ios - 创建模糊叠加 View

plot - Julia - 散点图 : how do I define different colors for each class?

减少使用 kable(, format = 'markdown' ) 创建的表中列之间的间距

algorithm - 如何平滑 3D 体素世界的 block ?

linux - Linux 桌面应用程序可以用作 Linux 桌面吗?

python - 向 python matplotlib 颜色条正确添加第二组刻度