28

The base R plot functions commonly use the argument lwd for specifying the line thickness. These are relative line widths though, and different help files indicate that this is a multiplying factor. So a linewidth lwd = 1 gives a line width of 1 * defaultwidth.

Where do I specify the default width for the line, or how can I make sure a line is eg specifically 0.75pt, as set in other software like Excel?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Joris Meys
  • 106,551
  • 31
  • 221
  • 263
  • 2
    Had the question, solved it myself, dropped it here for reference. Feel free to add to my answer, I'm still not 100% sure if I understood it all correctly. – Joris Meys Mar 07 '17 at 13:06

1 Answers1

30

The default line width is dependent on the device used for the plotting. In order to read this information, you should be aware of the general interpretation of inches, points and pixels. The general rules are:

  • a point is 1/72 of an inch
  • a pixel is standard 1/96 of an inch, or 0.75 points.

This can depend however on the settings of your device:

  • the pdf() and postscript() devices:
    • standard a point is seen as 1/72 inch
    • lwd = 1 refers to a linewidth of 1/96 inch or 0.75 points.
  • the png(), jpeg(), tiff() and bmp() devices:
    • standard a point is seen as 1/72 inch
    • this can be chanced by setting the argument res which defines the ppi (points per inch).
    • lwd = 1 is 1/96 of an inch but takes the settings of res into account. So if res = 96, lwd = 1 is a thickness of 1pt, but your point is interpreted smaller than a regular point.

Also keep in mind that with the bitmap devices, a higher setting of res will blow up your figure on screen. So in the previous example, a lwd = 1 with a setting of res = 96 gives a line with a thickness of 1pt, but shown on the same screen this will increase the line thickness from 1 pixel to 1.33 pixels. If you scale both figures to be exactly the same size, they look the same (apart from the resolution obviously).

See also:

How do I specify axis thickness in a plot? (in R)

Increasing the thickness of box lines in an R boxplot?

https://graphicdesign.stackexchange.com/questions/199/point-vs-pixel-what-is-the-difference

Community
  • 1
  • 1
Joris Meys
  • 106,551
  • 31
  • 221
  • 263
  • for me, `lwd=1` is too thin, `lwd=2` is too thick and it makes no difference using decimal values. Is there a `res` parameter that can be set? @JorisMeys – xm1 Aug 25 '18 at 00:20
  • 2
    @xm1 PDF doesn't have a res as that doesn't make sense in a vectorized image. You can try to set the `cex` parameter in your plotting, or `pointsize` in the `pdf()` function to get the result you want. – Joris Meys Aug 26 '18 at 12:44
  • I am plotting (`bxp`) to screen (RStudio) and using `lines` to add the "thick" line. It seems `cex` makes no difference to `lines`. Tks! – xm1 Aug 28 '18 at 14:09