【发布时间】:2015-12-30 04:02:42
【问题描述】:
曾几何时,我使用windowsFonts(Times=windowsFont("TT Times New Roman")) 更改了我的ggplot2 字体。现在,我无法摆脱它。
在尝试在ggplot2 theme() 中设置family="" 时,我似乎无法生成字体更改,因为我用不同的字体系列编译下面的MWE。
library(ggplot2)
library(extrafont)
loadfonts(device = "win")
a <- ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme(text=element_text(size=16,
# family="Comic Sans MS"))
# family="CM Roman"))
# family="TT Times New Roman"))
# family="Sans"))
family="Serif"))
print(a)
print("Graph should have refreshed")
R 返回警告font family not found in Windows font database,但我正在关注一个教程(如果我能再次找到它,我将在此处更新链接)说这是正常的,不是问题。此外,不知何故,这在某一时刻起作用,因为我的图表曾经使用过一些 arial 或 helvitica 字体。我认为即使在最初的迁移期间,这也一直是一个当前的警告。
更新
当我运行 windowsFonts() 时,我的输出是
$serif [1] "TT Times New Roman"
$sans [1] "TT Arial"
$mono [1] "TT Courier New"
但是,这是在我运行font_import() 之后,所以我只能得出结论,我的字体没有保存在正确的位置。运行font_import() 请求的代码实际上加载了库:
LocalLibraryLocation <- paste0("C:\\Users\\",Sys.getenv("USERNAME"),"\\Documents","\\R\\win-library\\3.2");
.libPaths(c(LocalLibraryLocation, .libPaths()))
【问题讨论】:
-
这是一个特定于 Windows 的问题和答案吗?有人想推广到 Linux 吗?
-
另外,
windowsFontsdisappeared from grDevices after 3.4.1。这里的代码需要更新。
标签: r ggplot2 fonts extrafont showtext