Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

In the below code, I just wanted to add a whole line or dotted line in a plot in R, from the South-West corner to the North-East corner basically from corner to corner. But the line does not go from corner to corner.

x.axis<-c(1.11, 0.67, 0.33, 0.33, 1.22, 0.67, 1.44, 2.67, 7.00, 5.00, 6.44, 2.78, 67.50, 65.40, 65.20, 68.00, 64.80, 62.40)

x.axis

y.axis<-c(26.056351,13.077900,8.882701,12.155014,20.150054,8.516783,6.185070,19.464096,17.700288,14.130253,5.778807,22.429427,

          52.611215, 8.286860,  36.316078,  62.010992,  82.822043,  41.747899)

y.axis

plot(x.axis,y.axis)

abline(a=0,b=1)

How to do that?

1 Answer

0 votes
by (108k points)

If you just want to plot a whole line from one corner to other corner then in that case you have to provide the points that are based on x and y limits of the plot figure. You can simply use the par() function and in that function pass 'usr' as argument:

# make the plot

plot(x.axis, y.axis)

# get axis limits

al = par("usr")

# plot a point to point line based on the axis limits

segments(al[1], al[3], al[2], al[4], col='pink')

corner to corner plot

If you are a beginner and want to know more about R then do refer to the following R programming tutorial that will help you in learning R from scratch.

Browse Categories

...