Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a line or add a text outside of the plot area in R?

Thank you for reading. I find that I am unable to draw lines/points or add text outside of the plot area. If I draw a line from inside the plot (within the axis) area to the area of the xlab main title areas only the part within the plot shows. In a multiple plot graph (mfrow) the line/point will only be drawn inside the last active plot.

plot(0);
l=locator(2,type='n');
lines(l, type='l'); 

Any solution to this problem? Thanks!

like image 807
Adam SO Avatar asked Aug 27 '10 14:08

Adam SO


People also ask

How do you add a line to a plot in R?

Use the lines() Function to Add a Line to a Plot in R Note that the second argument, which denotes the y-axis coordinates, is optional. Once the plot is drawn, we can call the lines() function and pass the coordinate vectors as needed to add lines to the plot.

What is XPD R?

xpd. parameter. This value specifies where in the plotting device an object can actually be plotted. The default is. xpd = FALSE.


1 Answers

The xpd parameter controls where you can draw. Check the current value with par()$xpd and then try setting par(xpd=NA).

From the par help:

 ‘xpd’ A logical value or ‘NA’.  If ‘FALSE’, all plotting is
      clipped to the plot region, if ‘TRUE’, all plotting is
      clipped to the figure region, and if ‘NA’, all plotting is
      clipped to the device region. See also ‘clip’.
like image 57
user1076 Avatar answered Oct 20 '22 19:10

user1076