简体   繁体   中英

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

在此处输入图片说明

2) Having same coordinate length. For the example above, you can see the max. value is 2.6 in total. So I want my scatter diagram as square. Both x and y coordinates lengths' must be 2.6.

3) I know how to export the plot manually. But which code should I use to export the plot?

1) Use abline to draw a straight line. This is called after your plot.

plot(data)
abline(0,1)

abline() also takes additional arguments, like col="red" .

2) This can be done using xlim and ylim . For more information on how you can edit the plot, use ?plot() inside R to see the revelant helpfile.

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.

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

Also works with jpeg, eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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