Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggsave does not constrain line width

Tags:

r

ggplot2

I have the following example

library(ggplot2)
library(ggthemes)
ggplot(mtcars) + 
  geom_point(aes(x = wt, y = mpg, colour=factor(gear))) + 
  facet_wrap(~am) +
  ggtitle("Title") +
  theme(
    axis.line.x = element_line(colour = "black", size = 0.5, linetype = "solid"),
    axis.line.y = element_line(colour = "black", size = 0.5, linetype = "solid")
  )

ggsave(filename = "~/Desktop/test.pdf")

In the docs of the element_line() function it is not specified which unit the size attribute has. But when I open the produced pdf in Illustrator the axis lines are shown as 1.07 pt lines.

So... what is the unit of the size attribute and how can I achieve that the output has a line width of 0.5 pt?

Thanks

like image 445
Pascal Avatar asked May 18 '26 04:05

Pascal


1 Answers

The conversion factor is (72.27/25.4)*(72.27/96)=2.141959. So, as you note, size=0.5 results in a line that is 1.07pt wide. See here for details.

like image 104
Claus Wilke Avatar answered May 20 '26 18:05

Claus Wilke