r – ggplot2 – 大小的單位
一個在網路上找不到答案的快速問題(或Wickham的書):
ggplot2中size引數的單位是多少?例如,geom_text(size = 10) –10在什麼單位?
編輯:同樣的問題適用於ggsave中的預設單位(height = 10,width = 10)
答案是:單位是積分.它是網格包中字型大小的單位.在單位中,我們找到以下定義
"points" Points. There are 72.27 points per inch.
(但注意密切相關的“bigpts”大點72 bp = 1 in.)
內部ggplot2將字型大小乘以魔術數字ggplot2 :::.pt,定義為1 / 0.352777778.
在這裡一個演示,我用grid和ggplot2建立一個相同大小的信件:
library(grid) library(ggplot2) ggplot(data=data.frame(x=1,y=1,label=c('A'))) + geom_text(aes(x,y,label=label),size=100) ## I divide by the magic number to get the same size. grid.text('A',gp=gpar(fontsize=100/0.352777778,col='red'))
感謝@baptiste的補充
“magic number”(在aaa-constants.r中定義為.pt<-1 / 0.352777778)實際上只是“點”和“mm”之間的轉換因子,即1/72 * 25.4 = 0.352777778.不幸的是,網格在“pts”和“bigpts”之間形成了微妙的區別,這就解釋了為什麼convertUnit(unit(1,“pt”),“mm”,valueOnly = TRUE)給出了0.3514598略有不同的值.
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/17311917/ggplot2-the-unit-of-size