A quick question that I can't find answer on the web (or Wickham's book):
What is the unit of the size argument in ggplot2? For example, geom_text(size=10) -- 10 in what units?
EDIT: The same question applies to default unit in ggsave(height=10, width=10)
The answer is : The unit is the points. It is the unit of fontsize in the
grid
package. In?unit
, we find the following definition(but note the closely related "bigpts"
Big Points. 72 bp = 1 in.
)Internally
ggplot2
will multiply the font size by a magic numberggplot2:::.pt
, defined as 1/0.352777778.Here a demonstration, I create a letter using grid and ggplot2 with same size:
Addendum Thanks to @baptiste
The "magic number"(defined in aaa-constants.r as .pt <- 1 / 0.352777778) is really just the conversion factor between "points" and "mm", that is
1/72 * 25.4 = 0.352777778
. Unfortunately,grid
makes the subtle distinction between "pts" and "bigpts", which explains whyconvertUnit(unit(1, "pt"), "mm", valueOnly=TRUE)
gives the slightly different value of0.3514598
.The 'ggplot2' package, like 'lattice' before it, is built on the
grid
package. You can get the available units at:(I use the formalism
pkg::func
because in most casesgrid
is loaded a a NAMESPACE but not attached when eitherlattice
or `ggplot2 are loaded.)I earlier posted a comment that I later deleted saying that
size
was in points. I did so after seeing that the size of the text withsize=10
was roughly 10 mm. The "magic" number mentioned by agstudy is in fact within 1% of:From
?aes_linetype_size_shape
height
andwidth
in ggsave relate topar("din")
from?par
So I guess
size
inaes
is in millimetres andggsave
height
andwidth
are in inches.