[This article was first published on One Tip Per Day, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I’ve drawn figure in R with lwd=1, e.g.
pdf(‘test.pdf’)plot(1:10, type=’o’, lwd=2, axes=F)
box(lwd=1, col=’red’)
dev.off()
And then you open the PDF in Illustrator, you will see the border width is 0.75pt, and the line is 1.5pt, which seems that the unit of 1 in R is 0.75pt in Illustrator.

How is this defined? Where can I change it?

I found the answer by switching the display unit of stroke in Illustrator (see below) from point to inch. It shows 1point=1pixel=0.0139inch=1/72 inch in Illustrator.

And in the R document of points(),  it says:
Value `pch = "."` (equivalently `pch = 46`) is handled specially. It is a rectangle of side 0.01 inch (scaled by `cex`). In addition, if `cex = 1` (the default), each side is at least one pixel (1/72 inch on the `pdf``postscript` and `xfig` devices).
For other text symbols, `cex = 1` corresponds to the default fontsize of the device, often specified by an argument `pointsize`. For `pch` in `0:25` the default size is about 75% of the character height (see `par("cin")`).
So, when saved into pdf, a point without scaling in R is one rectangle with one pixel each side, also 1/72 inch, which means the size of basic unit of R and illustrator should be same. But why lwd=1 will result in 0.75pt=3/4pixel in Illustrator? Is it set in PDF output?

OK. The answer is already in the pdf() document:
Line widths as controlled by `par(lwd = )` are in multiples of 1/96 inch. Multiples less than 1 are allowed. `pch = "."` with `cex = 1` corresponds to a square of side 1/72 inch, which is also the ‘pixel’ size assumed for graphics parameters such as `"cra"`.
So, lwd=1 is equal to 1/96 inch, which is exactly as 0.75 * 1/72 inch (0.75pt). To change it, for example if we want to set line width as 0.5 pt in Illustrator, we can set lwd=2/3, as below:
pdf(‘test2.pdf’)
par(lwd=2/3)
plot(1:10, type=’o’)
dev.off()
But I found this does not control the line width of axis and legend, which have to be set in the function itself.

btw, I have not figured it out how to get same setting for stroke line in R and in Illustrator. I was setting lty=’32’, lwd=2/3 in R, assuming that I can get stroke line as dash=1.5pt and gap=1pt in Illustrator, but actually I did not. Don’t know why. If anyone can figure it out, please let me know.

To leave a comment for the author, please follow the link and comment on their blog: One Tip Per Day.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

# Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)