简体   繁体   English

R中的散点图中的45度线和相同的坐标长度

[英]45 degree line and same coordinate lengths in scatter plot in R

I've two datas to compare in a scatter plot. 我有两个数据需要在散点图中进行比较。

data1 <-c(0.341, 0.655, 0.934, 1.741)
data2 <-c(1.8, 2, 2.4, 2.6)

With the code below I am getting this: 通过下面的代码,我得到了: 图形

plot(data1, data2, main="Minute Max.", asp=1,
      xlab="Historical Values ", ylab="Disaggregated Values", pch=19)

I have three wishes: 我有三个愿望:

1) Adding a 45 degree line 1)添加45度线

在此处输入图片说明

2) Having same coordinate length. 2)具有相同的坐标长度。 For the example above, you can see the max. 对于上面的示例,您可以看到最大 value is 2.6 in total. 总价值是2.6。 So I want my scatter diagram as square. 因此,我希望散点图为正方形。 Both x and y coordinates lengths' must be 2.6. x和y坐标长度都必须为2.6。

3) I know how to export the plot manually. 3)我知道如何手动导出图。 But which code should I use to export the plot? 但是我应该使用哪个代码来导出绘图?

1) Use abline to draw a straight line. 1)使用abline画一条直线。 This is called after your plot. 您的情节之后被称为。

plot(data)
abline(0,1)

abline() also takes additional arguments, like col="red" . abline()还接受其他参数,例如col="red"

2) This can be done using xlim and ylim . 2)这可以使用xlimylim For more information on how you can edit the plot, use ?plot() inside R to see the revelant helpfile. 有关如何编辑图的更多信息,请在R中使用?plot()查看最新的帮助文件。

plot(data, xlim=c(0,2.6),ylim=(0,2.6)

3) If you want it saved as eg a pdf, you can do the following. 3)如果要将其另存为pdf,则可以执行以下操作。

pdf("myfile.pdf")
plot(data,....)
dev.off()

Also works with jpeg, eg 也适用于jpeg,例如

jpeg("myplot.jpg")
plot(data)
dev.off()

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

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