我已按照xkcd简介(https://cran.r-project.org/web/packages/xkcd/vignettes/xkcd-intro.pdf)中的教程安装了“ xkcd”字体,并安装了xkcd软件包。
library(xkcd)
>fonts()
[1] "xkcd" "Agency FB"
[3] "Algerian" "Arial Black"
...
但是当尝试使用软件包中的第一个示例时,字体似乎没有显示出来:
if( 'xkcd' %in% fonts()) {
p <- ggplot() + geom_point(aes(x=mpg, y=wt), data=mtcars) +
theme(text = element_text(size = 16, family = "xkcd"))
} else {
warning("Not xkcd fonts installed!")
p <- ggplot() + geom_point(aes(x=mpg, y=wt), data=mtcars)
}
p
在使用mtcars示例时,我得到了这个尴尬的图:
xrange <- range(mtcars$mpg)
yrange <- range(mtcars$wt)
set.seed(123) # for reproducibility
p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) +
xkcdaxis(xrange,yrange)
p
很明显,我做错了什么,但是呢?
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xkcd_0.0.6 extrafont_0.17 bindrcpp_0.2.2 cowplot_0.9.3 emmeans_1.3.2 ggplot2_3.1.0
[7] nlme_3.1-137 dplyr_0.7.6 tidyr_0.8.1 lmerTest_3.0-1 lme4_1.1-18-1 Matrix_1.2-14
loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 mvtnorm_1.0-8 lattice_0.20-35 zoo_1.8-4
[5] digest_0.6.18 assertthat_0.2.0 utf8_1.1.4 R6_2.2.2
[9] plyr_1.8.4 backports_1.1.2 acepack_1.4.1 pillar_1.2.3
[13] rlang_0.2.2 lazyeval_0.2.1 multcomp_1.4-8 data.table_1.11.8
[17] rstudioapi_0.7 minqa_1.2.4 extrafontdb_1.0 nloptr_1.2.1
[21] rpart_4.1-13 checkmate_1.9.1 labeling_0.3 splines_3.5.0
[25] stringr_1.3.1 foreign_0.8-70 htmlwidgets_1.3 munsell_0.5.0
[29] compiler_3.5.0 numDeriv_2016.8-1 pkgconfig_2.0.2 base64enc_0.1-3
[33] htmltools_0.3.6 nnet_7.3-12 tidyselect_0.2.5 tibble_1.4.2
[37] gridExtra_2.3 htmlTable_1.13.1 Hmisc_4.2-0 codetools_0.2-15
[41] crayon_1.3.4 withr_2.1.2 MASS_7.3-49 grid_3.5.0
[45] xtable_1.8-3 Rttf2pt1_1.3.7 gtable_0.2.0 magrittr_1.5
[49] scales_1.0.0 stringi_1.1.7 estimability_1.3 cli_1.0.1
[53] latticeExtra_0.6-28 sandwich_2.5-0 Formula_1.2-3 TH.data_1.0-10
[57] RColorBrewer_1.1-2 tools_3.5.0 glue_1.3.0 purrr_0.2.5
[61] parallel_3.5.0 pbkrtest_0.4-7 survival_2.41-3 yaml_2.2.0
[65] colorspace_1.3-2 cluster_2.0.7-1 knitr_1.20 bindr_0.1.1