【r<-方案】如何修改画图使用的字体
2018-07-17 本文已影响25人
王诗翔
这是画图时都会存在的一个困惑,今天我终于尝试搜索和解决。
默认,R分为两类作图系统,一类是base plot,另一类是非基础绘图系统,像grid,以及基于它的ggplot2等。
对于基础的绘图系统,我们可以在使用plot
时设定family
参数,即可修改绘图字体。
例子:
> x = seq(1,10,1)
> y = 1.5*x
> windowsFonts(A = windowsFont("Times New Roman"))
> plot(x, y,
+ family="A",
+ main = "title",
+ font=2)
base plot
对于ggplot2
,我们需要设定主题theme
。
例子:
> windowsFonts(Times=windowsFont("Times New Roman"))
> library(ggplot2)
> ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
+ ggtitle("Fuel Efficiency of 32 Cars") +
+ xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
+ theme_bw() +
+ theme(text=element_text(family="Times", face="bold", size=12)) #Times New Roman, 12pt, Bold
ggplot2
如果你仔细看了上面的代码,你会发现上面两种设定解决方案都是一致的,只不过不同的绘图系统设置方式不同,它们都通过windowsFonts()
实现。
从函数名就可以看出,它不能适用于其他系统,比如linux
> windowsFonts(Times=windowsFont("Times New Roman"))
Error in windowsFonts(Times = windowsFont("Times New Roman")) :
could not find function "windowsFonts"
extrafont包
extrafont package 提供了更多的特性,它的操作更为普适,而且它可以导入系统中的字体库!这样我们在绘图时有了更多的选择。
安装:
p_load(extrafont)
# or
install.packages("extrafont", dependencies=TRUE)
library(extrafont)
推荐使用
pacman
包管理包,它可以让代码更简洁,可以更简洁从CRAN,Github,以及bioconductor下载、安装以及加载包等,见【r<-包】管理你的R包——pacman包介绍
然后导入字体
> font_import()
Importing fonts may take a few minutes, depending on the number of fonts and the speed of the system.
Continue? [y/n] y
Scanning ttf files in C:\Windows\Fonts ...
Extracting .afm files from .ttf files...
C:\Windows\Fonts\AGENCYB.TTF => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/AGENCYB
C:\Windows\Fonts\AGENCYR.TTF => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/AGENCYR
C:\Windows\Fonts\ahronbd.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/ahronbd
C:\Windows\Fonts\ALGER.TTF => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/ALGER
C:\Windows\Fonts\andlso.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/andlso
C:\Windows\Fonts\angsa.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsa
C:\Windows\Fonts\angsab.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsab
C:\Windows\Fonts\angsai.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsai
C:\Windows\Fonts\angsau.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsau
C:\Windows\Fonts\angsaub.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsaub
C:\Windows\Fonts\angsaui.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsaui
C:\Windows\Fonts\angsauz.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsauz
C:\Windows\Fonts\angsaz.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/angsaz
C:\Windows\Fonts\ANTQUAB.TTF => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/ANTQUAB
C:\Windows\Fonts\ANTQUABI.TTF => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/ANTQUABI
C:\Windows\Fonts\ANTQUAI.TTF => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/ANTQUAI
C:\Windows\Fonts\aparaj.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/aparaj
C:\Windows\Fonts\aparajb.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/aparajb
C:\Windows\Fonts\aparajbi.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/aparajbi
C:\Windows\Fonts\aparaji.ttf => C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics/aparaji
...
Found FontName for 544 fonts.
Scanning afm files in C:/Program Files/R/R-3.5.0/library/extrafontdb/metrics
Writing font table in C:/Program Files/R/R-3.5.0/library/extrafontdb/fontmap/fonttable.csv
Writing Fontmap to C:/Program Files/R/R-3.5.0/library/extrafontdb/fontmap/Fontmap...
加载和查看字体:
> loadfonts(device="win") #Register fonts for Windows bitmap output
#device参数 The output device. Can be "pdf" (the default), "postscript", or "win".
Registering font with R using windowsFonts(): Agency FB
Registering font with R using windowsFonts(): Aharoni
Registering font with R using windowsFonts(): Algerian
Registering font with R using windowsFonts(): Andalus
Registering font with R using windowsFonts(): Angsana New
Registering font with R using windowsFonts(): AngsanaUPC
Registering font with R using windowsFonts(): Aparajita
Registering font with R using windowsFonts(): Arabic Typesetting
Registering font with R using windowsFonts(): Arial Black
Registering font with R using windowsFonts(): Arial
Registering font with R using windowsFonts(): Arial Narrow
Registering font with R using windowsFonts(): Arial Rounded MT Bold
Registering font with R using windowsFonts(): Arial Unicode MS
Registering font with R using windowsFonts(): Baskerville Old Face
Registering font with R using windowsFonts(): Bauhaus 93
Registering font with R using windowsFonts(): Bell MT
Registering font with R using windowsFonts(): Berlin Sans FB
Registering font with R using windowsFonts(): Berlin Sans FB Demi
Registering font with R using windowsFonts(): Bernard MT Condensed
Registering font with R using windowsFonts(): Blackadder ITC
Registering font with R using windowsFonts(): Bodoni Bd BT
Registering font with R using windowsFonts(): Bodoni Bk BT
Registering font with R using windowsFonts(): Bodoni MT
Registering font with R using windowsFonts(): Bodoni MT Black
Registering font with R using windowsFonts(): Bodoni MT Condensed
Registering font with R using windowsFonts(): Bodoni MT Poster Compressed
Registering font with R using windowsFonts(): Book Antiqua
Registering font with R using windowsFonts(): Bookman Old Style
Registering font with R using windowsFonts(): Bookshelf Symbol 7
Registering font with R using windowsFonts(): Bradley Hand ITC
Registering font with R using windowsFonts(): Britannic Bold
Registering font with R using windowsFonts(): Broadway
Registering font with R using windowsFonts(): Browallia New
Registering font with R using windowsFonts(): BrowalliaUPC
Registering font with R using windowsFonts(): Brush Script MT
Registering font with R using windowsFonts(): Calibri
Registering font with R using windowsFonts(): Calibri Light
Registering font with R using windowsFonts(): Californian FB
Registering font with R using windowsFonts(): Calisto MT
Registering font with R using windowsFonts(): Cambria
Registering font with R using windowsFonts(): Candara
Registering font with R using windowsFonts(): Castellar
Registering font with R using windowsFonts(): Centaur
Registering font with R using windowsFonts(): Century
Registering font with R using windowsFonts(): Century725 Cn BT
Registering font with R using windowsFonts(): Century751 No2 BT
Registering font with R using windowsFonts(): Century751 BT
Registering font with R using windowsFonts(): Century751 SeBd BT
Registering font with R using windowsFonts(): Century Gothic
Registering font with R using windowsFonts(): CentSchbkCyrill BT
Registering font with R using windowsFonts(): Century Schoolbook
Registering font with R using windowsFonts(): Chiller
Registering font with R using windowsFonts(): Clarendon Blk BT
Registering font with R using windowsFonts(): Clarendon BT
Registering font with R using windowsFonts(): Clarendon Lt BT
Registering font with R using windowsFonts(): Colonna MT
Registering font with R using windowsFonts(): Comic Sans MS
Registering font with R using windowsFonts(): Consolas
Registering font with R using windowsFonts(): Constantia
Registering font with R using windowsFonts(): Cooper Black
Registering font with R using windowsFonts(): Copperplate Gothic Bold
Registering font with R using windowsFonts(): Copperplate Gothic Light
Registering font with R using windowsFonts(): Corbel
Registering font with R using windowsFonts(): Cordia New
Registering font with R using windowsFonts(): CordiaUPC
Registering font with R using windowsFonts(): Courier New
Registering font with R using windowsFonts(): Curlz MT
Registering font with R using windowsFonts(): DaunPenh
Registering font with R using windowsFonts(): David
Registering font with R using windowsFonts(): DejaVu Sans Mono
Registering font with R using windowsFonts(): DengXian
Registering font with R using windowsFonts(): DengXian Light
Registering font with R using windowsFonts(): DeVinne Txt BT
Registering font with R using windowsFonts(): DFGothic-EB
Registering font with R using windowsFonts(): DFKaiSho-SB
Registering font with R using windowsFonts(): DFKai-SB
Registering font with R using windowsFonts(): DFMincho-SU
Registering font with R using windowsFonts(): DFMincho-UB
Registering font with R using windowsFonts(): DFMincho-W5
Registering font with R using windowsFonts(): DFPOP1-W9
Registering font with R using windowsFonts(): DilleniaUPC
Registering font with R using windowsFonts(): DokChampa
Registering font with R using windowsFonts(): Ebrima
Registering font with R using windowsFonts(): Edwardian Script ITC
Registering font with R using windowsFonts(): Elephant
Registering font with R using windowsFonts(): Embassy BT
Registering font with R using windowsFonts(): EngraversGothic BT
Registering font with R using windowsFonts(): Engravers MT
Registering font with R using windowsFonts(): Eras Bold ITC
Registering font with R using windowsFonts(): Eras Demi ITC
Registering font with R using windowsFonts(): Eras Light ITC
Registering font with R using windowsFonts(): Eras Medium ITC
Registering font with R using windowsFonts(): Estrangelo Edessa
Registering font with R using windowsFonts(): EucrosiaUPC
Registering font with R using windowsFonts(): Euphemia
Registering font with R using windowsFonts(): Exotc350 Bd BT
Registering font with R using windowsFonts(): Exotc350 DmBd BT
Registering font with R using windowsFonts(): FangSong
Registering font with R using windowsFonts(): Felix Titling
Registering font with R using windowsFonts(): Footlight MT Light
Registering font with R using windowsFonts(): Forte
Registering font with R using windowsFonts(): Franklin Gothic Book
Registering font with R using windowsFonts(): Franklin Gothic Demi
Registering font with R using windowsFonts(): Franklin Gothic Demi Cond
Registering font with R using windowsFonts(): Franklin Gothic Heavy
Registering font with R using windowsFonts(): Franklin Gothic Medium
Registering font with R using windowsFonts(): Franklin Gothic Medium Cond
Registering font with R using windowsFonts(): FrankRuehl
Registering font with R using windowsFonts(): Freehand521 BT
Registering font with R using windowsFonts(): FreesiaUPC
Registering font with R using windowsFonts(): Freestyle Script
Registering font with R using windowsFonts(): French Script MT
Registering font with R using windowsFonts(): Futura Md BT
Registering font with R using windowsFonts(): Futura Bk BT
Registering font with R using windowsFonts(): FZLanTingHeiS-UL-GB
Registering font with R using windowsFonts(): FZShuTi
Registering font with R using windowsFonts(): FZYaoTi
Registering font with R using windowsFonts(): Gabriola
Registering font with R using windowsFonts(): Gadugi
Registering font with R using windowsFonts(): Garamond
Registering font with R using windowsFonts(): Gautami
Registering font with R using windowsFonts(): Geometr212 BkCn BT
Registering font with R using windowsFonts(): Geometr415 Blk BT
Registering font with R using windowsFonts(): Geometr706 BlkCn BT
Registering font with R using windowsFonts(): GeoSlab703 Md BT
Registering font with R using windowsFonts(): GeoSlab703 MdCn BT
Registering font with R using windowsFonts(): Georgia
Registering font with R using windowsFonts(): Gigi
Registering font with R using windowsFonts(): Gill Sans Ultra Bold
Registering font with R using windowsFonts(): Gill Sans Ultra Bold Condensed
Registering font with R using windowsFonts(): Gill Sans MT
Registering font with R using windowsFonts(): Gill Sans MT Condensed
Registering font with R using windowsFonts(): Gill Sans MT Ext Condensed Bold
Registering font with R using windowsFonts(): Gisha
Registering font with R using windowsFonts(): Gloucester MT Extra Condensed
Registering font with R using windowsFonts(): Goudy Old Style
Registering font with R using windowsFonts(): Goudy Stout
Registering font with R using windowsFonts(): Haettenschweiler
Registering font with R using windowsFonts(): Harlow Solid Italic
Registering font with R using windowsFonts(): Harrington
Registering font with R using windowsFonts(): High Tower Text
Registering font with R using windowsFonts(): Humanst521 BT
Registering font with R using windowsFonts(): Humanst521 Lt BT
Registering font with R using windowsFonts(): Humnst777 Blk BT
Registering font with R using windowsFonts(): Humnst777 BlkCn BT
Registering font with R using windowsFonts(): Humnst777 Cn BT
Registering font with R using windowsFonts(): Humnst777 Lt BT
Registering font with R using windowsFonts(): Humnst777 BT
Registering font with R using windowsFonts(): Impact
Registering font with R using windowsFonts(): Imprint MT Shadow
Registering font with R using windowsFonts(): Informal Roman
Registering font with R using windowsFonts(): IrisUPC
Registering font with R using windowsFonts(): Iskoola Pota
Registering font with R using windowsFonts(): JasmineUPC
Registering font with R using windowsFonts(): Jokerman
Registering font with R using windowsFonts(): Juice ITC
Registering font with R using windowsFonts(): KaiTi
Registering font with R using windowsFonts(): Kalinga
Registering font with R using windowsFonts(): Kartika
Registering font with R using windowsFonts(): Kaufmann BT
Registering font with R using windowsFonts(): Khmer UI
Registering font with R using windowsFonts(): KodchiangUPC
Registering font with R using windowsFonts(): Kokila
Registering font with R using windowsFonts(): Kristen ITC
Registering font with R using windowsFonts(): Kunstler Script
Registering font with R using windowsFonts(): Lao UI
Registering font with R using windowsFonts(): Latha
Registering font with R using windowsFonts(): Wide Latin
Registering font with R using windowsFonts(): Leelawadee
Registering font with R using windowsFonts(): Levenim MT
Registering font with R using windowsFonts(): LilyUPC
Registering font with R using windowsFonts(): LiSu
Registering font with R using windowsFonts(): Lucida Bright
Registering font with R using windowsFonts(): Lucida Calligraphy
Registering font with R using windowsFonts(): Lucida Console
Registering font with R using windowsFonts(): Lucida Fax
Registering font with R using windowsFonts(): Lucida Handwriting
Registering font with R using windowsFonts(): Lucida Sans
Registering font with R using windowsFonts(): Lucida Sans Typewriter
Registering font with R using windowsFonts(): Lucida Sans Unicode
Registering font with R using windowsFonts(): Magneto
Registering font with R using windowsFonts(): Maiandra GD
Registering font with R using windowsFonts(): Malgun Gothic
Registering font with R using windowsFonts(): Mangal
Registering font with R using windowsFonts(): Marlett
Registering font with R using windowsFonts(): Matura MT Script Capitals
Registering font with R using windowsFonts(): Microsoft Yi Baiti
Registering font with R using windowsFonts(): Microsoft Himalaya
Registering font with R using windowsFonts(): Microsoft JhengHei
Registering font with R using windowsFonts(): Microsoft New Tai Lue
Registering font with R using windowsFonts(): Microsoft PhagsPa
Registering font with R using windowsFonts(): Microsoft Sans Serif
Registering font with R using windowsFonts(): Microsoft Tai Le
Registering font with R using windowsFonts(): Microsoft Uighur
Registering font with R using windowsFonts(): Microsoft YaHei
Registering font with R using windowsFonts(): Miriam
Registering font with R using windowsFonts(): Miriam Fixed
Registering font with R using windowsFonts(): Mistral
Registering font with R using windowsFonts(): Modern No. 20
Registering font with R using windowsFonts(): Monaco
Registering font with R using windowsFonts(): Mongolian Baiti
Registering font with R using windowsFonts(): Monotype Corsiva
Registering font with R using windowsFonts(): MoolBoran
Registering font with R using windowsFonts(): MS Outlook
Registering font with R using windowsFonts(): MS Reference Sans Serif
Registering font with R using windowsFonts(): MS Reference Specialty
Registering font with R using windowsFonts(): MV Boli
Registering font with R using windowsFonts(): Narkisim
Registering font with R using windowsFonts(): News701 BT
Registering font with R using windowsFonts(): News706 BT
Registering font with R using windowsFonts(): NewsGoth BT
Registering font with R using windowsFonts(): NewsGoth Lt BT
Registering font with R using windowsFonts(): NewsGoth Cn BT
Registering font with R using windowsFonts(): Niagara Engraved
Registering font with R using windowsFonts(): Niagara Solid
Registering font with R using windowsFonts(): Nirmala UI
Registering font with R using windowsFonts(): Nyala
Registering font with R using windowsFonts(): OCR-A BT
Registering font with R using windowsFonts(): OCR A Extended
Registering font with R using windowsFonts(): OCR-B 10 BT
Registering font with R using windowsFonts(): Old English Text MT
Registering font with R using windowsFonts(): Onyx
Registering font with R using windowsFonts(): Palace Script MT
Registering font with R using windowsFonts(): Palatino Linotype
Registering font with R using windowsFonts(): Papyrus
Registering font with R using windowsFonts(): Parchment
Registering font with R using windowsFonts(): Perpetua
Registering font with R using windowsFonts(): Perpetua Titling MT
Registering font with R using windowsFonts(): Plantagenet Cherokee
Registering font with R using windowsFonts(): Playbill
Registering font with R using windowsFonts(): Poor Richard
Registering font with R using windowsFonts(): Pristina
Registering font with R using windowsFonts(): Raavi
Registering font with R using windowsFonts(): Rage Italic
Registering font with R using windowsFonts(): Ravie
Registering font with R using windowsFonts(): Rockwell
Registering font with R using windowsFonts(): Rockwell Condensed
Registering font with R using windowsFonts(): Rockwell Extra Bold
Registering font with R using windowsFonts(): Rod
Registering font with R using windowsFonts(): Sakkal Majalla
Registering font with R using windowsFonts(): Schadow BT
Registering font with R using windowsFonts(): Script MT Bold
Registering font with R using windowsFonts(): Segoe Print
Registering font with R using windowsFonts(): Segoe Script
Registering font with R using windowsFonts(): Segoe UI
Registering font with R using windowsFonts(): Segoe UI Light
Registering font with R using windowsFonts(): Segoe UI Semibold
Registering font with R using windowsFonts(): Segoe UI Semilight
Registering font with R using windowsFonts(): Segoe UI Emoji
Registering font with R using windowsFonts(): Segoe UI Symbol
Registering font with R using windowsFonts(): Shonar Bangla
Registering font with R using windowsFonts(): Showcard Gothic
Registering font with R using windowsFonts(): Shruti
Registering font with R using windowsFonts(): SimHei
Registering font with R using windowsFonts(): Simplified Arabic
Registering font with R using windowsFonts(): Simplified Arabic Fixed
Registering font with R using windowsFonts(): SimSun-ExtB
Registering font with R using windowsFonts(): Snap ITC
Registering font with R using windowsFonts(): Square721 BT
Registering font with R using windowsFonts(): Square721 Cn BT
Registering font with R using windowsFonts(): STCaiyun
Registering font with R using windowsFonts(): Stencil
Registering font with R using windowsFonts(): STFangsong
Registering font with R using windowsFonts(): STHupo
Registering font with R using windowsFonts(): STKaiti
Registering font with R using windowsFonts(): STLiti
Registering font with R using windowsFonts(): STSong
Registering font with R using windowsFonts(): STXihei
Registering font with R using windowsFonts(): STXingkai
Registering font with R using windowsFonts(): STXinwei
Registering font with R using windowsFonts(): STZhongsong
Registering font with R using windowsFonts(): Swis721 Blk BT
Registering font with R using windowsFonts(): Swis721 BlkCn BT
Registering font with R using windowsFonts(): Swis721 WGL4 BT
Registering font with R using windowsFonts(): Swis721 BT
Registering font with R using windowsFonts(): Swis721 Cn BT
Registering font with R using windowsFonts(): Swis721 Hv BT
Registering font with R using windowsFonts(): Swis721 Lt BT
Registering font with R using windowsFonts(): Swis721 LtEx BT
Registering font with R using windowsFonts(): Sylfaen
Registering font with R using windowsFonts(): Symbol
Registering font with R using windowsFonts(): Tahoma
Registering font with R using windowsFonts(): Tempus Sans ITC
Registering font with R using windowsFonts(): Times New Roman
Registering font with R using windowsFonts(): Traditional Arabic
Registering font with R using windowsFonts(): Trebuchet MS
Registering font with R using windowsFonts(): Tunga
Registering font with R using windowsFonts(): Tw Cen MT
Registering font with R using windowsFonts(): Tw Cen MT Condensed
Registering font with R using windowsFonts(): Tw Cen MT Condensed Extra Bold
Registering font with R using windowsFonts(): TypoUpright BT
Registering font with R using windowsFonts(): Utsaah
Registering font with R using windowsFonts(): Vani
Registering font with R using windowsFonts(): Verdana
Registering font with R using windowsFonts(): Vijaya
Registering font with R using windowsFonts(): Viner Hand ITC
Registering font with R using windowsFonts(): Vivaldi
Registering font with R using windowsFonts(): Vladimir Script
Registering font with R using windowsFonts(): Vrinda
Registering font with R using windowsFonts(): Webdings
Registering font with R using windowsFonts(): Wingdings
Registering font with R using windowsFonts(): Wingdings 2
Registering font with R using windowsFonts(): Wingdings 3
Registering font with R using windowsFonts(): YouYuan
> fonts() #vector of font family names
[1] "Agency FB" "Aharoni" "Algerian"
[4] "Andalus" "Angsana New" "AngsanaUPC"
[7] "Aparajita" "Arabic Typesetting" "Arial Black"
[10] "Arial" "Arial Narrow" "Arial Rounded MT Bold"
[13] "Arial Unicode MS" "Baskerville Old Face" "Bauhaus 93"
[16] "Bell MT" "Berlin Sans FB" "Berlin Sans FB Demi"
[19] "Bernard MT Condensed" "Blackadder ITC" "Bodoni Bd BT"
[22] "Bodoni Bk BT" "Bodoni MT" "Bodoni MT Black"
[25] "Bodoni MT Condensed" "Bodoni MT Poster Compressed" "Book Antiqua"
[28] "Bookman Old Style" "Bookshelf Symbol 7" "Bradley Hand ITC"
[31] "Britannic Bold" "Broadway" "Browallia New"
[34] "BrowalliaUPC" "Brush Script MT" "Calibri"
[37] "Calibri Light" "Californian FB" "Calisto MT"
[40] "Cambria" "Candara" "Castellar"
[43] "Centaur" "Century" "Century725 Cn BT"
[46] "Century751 No2 BT" "Century751 BT" "Century751 SeBd BT"
[49] "Century Gothic" "CentSchbkCyrill BT" "Century Schoolbook"
[52] "Chiller" "Clarendon Blk BT" "Clarendon BT"
[55] "Clarendon Lt BT" "Colonna MT" "Comic Sans MS"
[58] "Consolas" "Constantia" "Cooper Black"
[61] "Copperplate Gothic Bold" "Copperplate Gothic Light" "Corbel"
[64] "Cordia New" "CordiaUPC" "Courier New"
[67] "Curlz MT" "DaunPenh" "David"
[70] "DejaVu Sans Mono" "DengXian" "DengXian Light"
[73] "DeVinne Txt BT" "DFGothic-EB" "DFKaiSho-SB"
[76] "DFKai-SB" "DFMincho-SU" "DFMincho-UB"
[79] "DFMincho-W5" "DFPOP1-W9" "DilleniaUPC"
[82] "DokChampa" "Ebrima" "Edwardian Script ITC"
[85] "Elephant" "Embassy BT" "EngraversGothic BT"
[88] "Engravers MT" "Eras Bold ITC" "Eras Demi ITC"
[91] "Eras Light ITC" "Eras Medium ITC" "Estrangelo Edessa"
[94] "EucrosiaUPC" "Euphemia" "Exotc350 Bd BT"
[97] "Exotc350 DmBd BT" "FangSong" "Felix Titling"
[100] "Footlight MT Light" "Forte" "Franklin Gothic Book"
[103] "Franklin Gothic Demi" "Franklin Gothic Demi Cond" "Franklin Gothic Heavy"
[106] "Franklin Gothic Medium" "Franklin Gothic Medium Cond" "FrankRuehl"
[109] "Freehand521 BT" "FreesiaUPC" "Freestyle Script"
[112] "French Script MT" "Futura Md BT" "Futura Bk BT"
[115] "FZLanTingHeiS-UL-GB" "FZShuTi" "FZYaoTi"
[118] "Gabriola" "Gadugi" "Garamond"
[121] "Gautami" "Geometr212 BkCn BT" "Geometr415 Blk BT"
[124] "Geometr706 BlkCn BT" "GeoSlab703 Md BT" "GeoSlab703 MdCn BT"
[127] "Georgia" "Gigi" "Gill Sans Ultra Bold"
[130] "Gill Sans Ultra Bold Condensed" "Gill Sans MT" "Gill Sans MT Condensed"
[133] "Gill Sans MT Ext Condensed Bold" "Gisha" "Gloucester MT Extra Condensed"
[136] "Goudy Old Style" "Goudy Stout" "Haettenschweiler"
[139] "Harlow Solid Italic" "Harrington" "High Tower Text"
[142] "Humanst521 BT" "Humanst521 Lt BT" "Humnst777 Blk BT"
[145] "Humnst777 BlkCn BT" "Humnst777 Cn BT" "Humnst777 Lt BT"
[148] "Humnst777 BT" "Impact" "Imprint MT Shadow"
[151] "Informal Roman" "IrisUPC" "Iskoola Pota"
[154] "JasmineUPC" "Jokerman" "Juice ITC"
[157] "KaiTi" "Kalinga" "Kartika"
[160] "Kaufmann BT" "Khmer UI" "KodchiangUPC"
[163] "Kokila" "Kristen ITC" "Kunstler Script"
[166] "Lao UI" "Latha" "Wide Latin"
[169] "Leelawadee" "Levenim MT" "LilyUPC"
[172] "LiSu" "Lucida Bright" "Lucida Calligraphy"
[175] "Lucida Console" "Lucida Fax" "Lucida Handwriting"
[178] "Lucida Sans" "Lucida Sans Typewriter" "Lucida Sans Unicode"
[181] "Magneto" "Maiandra GD" "Malgun Gothic"
[184] "Mangal" "Marlett" "Matura MT Script Capitals"
[187] "Microsoft Yi Baiti" "Microsoft Himalaya" "Microsoft JhengHei"
[190] "Microsoft New Tai Lue" "Microsoft PhagsPa" "Microsoft Sans Serif"
[193] "Microsoft Tai Le" "Microsoft Uighur" "Microsoft YaHei"
[196] "Miriam" "Miriam Fixed" "Mistral"
[199] "Modern No. 20" "Monaco" "Mongolian Baiti"
[202] "Monotype Corsiva" "MoolBoran" "MS Outlook"
[205] "MS Reference Sans Serif" "MS Reference Specialty" "MV Boli"
[208] "Narkisim" "News701 BT" "News706 BT"
[211] "NewsGoth BT" "NewsGoth Lt BT" "NewsGoth Cn BT"
[214] "Niagara Engraved" "Niagara Solid" "Nirmala UI"
[217] "Nyala" "OCR-A BT" "OCR A Extended"
[220] "OCR-B 10 BT" "Old English Text MT" "Onyx"
[223] "Palace Script MT" "Palatino Linotype" "Papyrus"
[226] "Parchment" "Perpetua" "Perpetua Titling MT"
[229] "Plantagenet Cherokee" "Playbill" "Poor Richard"
[232] "Pristina" "Raavi" "Rage Italic"
[235] "Ravie" "Rockwell" "Rockwell Condensed"
[238] "Rockwell Extra Bold" "Rod" "Sakkal Majalla"
[241] "Schadow BT" "Script MT Bold" "Segoe Print"
[244] "Segoe Script" "Segoe UI" "Segoe UI Light"
[247] "Segoe UI Semibold" "Segoe UI Semilight" "Segoe UI Emoji"
[250] "Segoe UI Symbol" "Shonar Bangla" "Showcard Gothic"
[253] "Shruti" "SimHei" "Simplified Arabic"
[256] "Simplified Arabic Fixed" "SimSun-ExtB" "Snap ITC"
[259] "Square721 BT" "Square721 Cn BT" "STCaiyun"
[262] "Stencil" "STFangsong" "STHupo"
[265] "STKaiti" "STLiti" "STSong"
[268] "STXihei" "STXingkai" "STXinwei"
[271] "STZhongsong" "Swis721 Blk BT" "Swis721 BlkCn BT"
[274] "Swis721 WGL4 BT" "Swis721 BT" "Swis721 Cn BT"
[277] "Swis721 Hv BT" "Swis721 Lt BT" "Swis721 LtEx BT"
[280] "Sylfaen" "Symbol" "Tahoma"
[283] "Tempus Sans ITC" "Times New Roman" "Traditional Arabic"
[286] "Trebuchet MS" "Tunga" "Tw Cen MT"
[289] "Tw Cen MT Condensed" "Tw Cen MT Condensed Extra Bold" "TypoUpright BT"
[292] "Utsaah" "Vani" "Verdana"
[295] "Vijaya" "Viner Hand ITC" "Vivaldi"
[298] "Vladimir Script" "Vrinda" "Webdings"
[301] "Wingdings" "Wingdings 2" "Wingdings 3"
[304] "YouYuan"
>
画图使用字体:
> ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
+ ggtitle("Fuel Efficiency of 32 Cars") +
+ xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
+ theme_bw() +
+ theme(text=element_text(family="YouYuan", face="bold", size=12))
Youyuan字体
记住,每次注册字体库都只能在当前线程中使用,如果重启R线程需要重新载入,就是再运行一次loadfonts(device="win")
。
另外非windows系统设定device="win"
是没用的,默认不用设定参数即可。
更详细内容见包文档:https://github.com/wch/extrafont/
参考:
https://stackoverflow.com/questions/27689222/changing-fonts-for-graphs-in-r