相关疑难解决方法(0)

更改ggplot2中的字体

曾几何时,我ggplot2使用windowsFonts(Times=windowsFont("TT Times New Roman"))改变它来改变我的字体.现在我无法理解这一点.

在尝试设置family=""ggplot2 theme()我似乎无法生成字体更改,因为我使用不同的字体系列编译下面的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")
Run Code Online (Sandbox Code Playgroud)

R正在返回一个警告font family not found in Windows font database,但有一个我正在关注的教程(如果我能再次找到它,我将在这里更新链接)说这是正常的而不是问题.此外,这在某种程度上起作用,因为我的图表曾经使用过一些arial或helvitica类型的字体.我认为即使在最初的迁移期间,这也始终是一个警告.

UPDATE

当我运行windowsFonts()我的输出是

$ serif [1]"TT Times …

fonts r ggplot2 showtext extrafont

56
推荐指数
4
解决办法
8万
查看次数

字体家族不会在ggplot中更改

我的情节是可行的,除了我无法更改字体系列。即使我可以更改其他内容(例如颜色,大小和对齐方式),它也始终保持默认值。

这是我的代码:

ggplot(data = SeattleJuly17Data,
       aes(x = Price, y = SatisfactionScore, col = RoomType)) +
    geom_point() +
    xlim(0,500) +
    geom_smooth() +
    ggtitle("Satisfaction Trends by Price and Room Type") +
    theme(plot.title = element_text(family = "Calibri",
                                    size=15,
                                    color="Red",
                                    hjust = 0.5)) +
    xlab("Price per Night") +
    ylab("Guest Satisfaction Score")
Run Code Online (Sandbox Code Playgroud)

fonts r ggplot2 extrafont

5
推荐指数
1
解决办法
548
查看次数

标签 统计

extrafont ×2

fonts ×2

ggplot2 ×2

r ×2

showtext ×1