标签: showtext

更改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万
查看次数

ggsave() 不会将文本加粗,它会更改所有文本的字体而不仅仅是绘图标题

我正在 ggplot2 中制作图表,但ggsave()没有达到我的预期。

require(ggplot2)
require(showtext)

showtext_auto()
hedFont <- "Pragati Narrow"
font_add_google(
  name = hedFont,
  family = hedFont,
  regular.wt = 400,
  bold.wt = 700
)

chart <- ggplot(
  data = cars,
  aes(
    x = speed,
    y = dist
  )
) +
  geom_point() +
  labs(
    title = "Here is a title",
    subtitle = "Subtitle here"
  ) +
  theme(
    plot.title = element_text(
      size = 20,
      family = hedFont,
      face = "bold"
    ),
    axis.title = element_text(
      face = "bold"
    )
  )

ggsave( …
Run Code Online (Sandbox Code Playgroud)

fonts r ggplot2 showtext extrafont

8
推荐指数
2
解决办法
5081
查看次数

MATLAB R2019a 中的轮廓函数中“ShowText”和“LineStyle”之间的冲突?

我使用的代码如下。但是当我在 MATLAB R2014a 和 R2019a(在同一台计算机,Win7 64 位)中运行我的代码时,数字是不同的。MATLAB R2019a中的函数'ShowText''LineStyle'函数之间似乎存在冲突contourf?我想要的是带有文本且没有线条的图形(如 R2014a 的图形)。我怎样才能在 R2019a 中获得它?

for i = 1 : 10
    for j = 1 : 10
        res(i, j) = i * j;
    end
end
contourf(res, 'ShowText', 'on', 'LineStyle', 'none');
Run Code Online (Sandbox Code Playgroud)

图使用 R2014a

图由 R2014a

图使用 R2019a

图由 R2019a

图使用 R2019acontourf(res, 'ShowText', 'on')只使用

图由 R2019a 仅使用“contourf(res, 'ShowText', 'on')

matlab linestyle matlab-figure contourf showtext

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

显示文本 font_add_google 中未加载字体

我正在尝试绘制一些数据的图表,我的代码如下所示:

library('ggplot2')
library('tidyr')
library('ggthemes')
library('showtext')

font_add_google('Syncopate', 'Syncopate')
showtext_auto()

ggplot(aes(x = X, group=1), data = glassdoor)+
  geom_line(aes(y = col1, color = 'red'))+
  geom_line(aes(y = col2, color = 'blue'))+
  geom_line(aes(y = col3, color = 'magenta'))+
  geom_line(aes(y = col4, color = 'yellow'))+
  theme(text = element_text(family = "Syncopate"))+
  ggtitle('A Long Test Title')
Run Code Online (Sandbox Code Playgroud)

切分音是一种独特的字体,请参见此处。但我的可视化字体看起来像这样(这是一个测试图,忽略其整体的糟糕性):

在此输入图像描述

但如果我加载像 Times New Roman 这样的系统主题,它就可以正常工作。为什么我的谷歌字体不使用 showtext 加载?

编辑

Jrakru 的答案有效,但请记住,您必须运行整个代码块:新字体将出现在保存的 png 文件中,但不会出现在预览窗口中。这并不是对答案的轻微反对,而是针对像我这样希望字体显示在 RStudio 控制台中的其他人,因此省略了代码的ggsave和部分。png

r ggplot2 showtext

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

在没有管理员权限的 RMarkdown 主体中使用 Google 字体

我想定义要在我的 RMarkdown PDF 文档中使用的字体。我想使用 Google 字体,例如 Roboto,但我没有直接安装它的管理员权限。尽管如此,我认为我可以解决这些特权,因为我已经安装了许多带有自己的字体(例如,tint)的R 包。

通常,要为降价文档设置自定义字体,我会在 YAML 中执行以下操作:

---
title: "Title"
output:
  pdf_document:
    latex_engine: xelatex
mainfont: Calibri
---
Run Code Online (Sandbox Code Playgroud)

如果安装了字体,这会起作用,但是,正如我所说,我无法安装字体。我可以通过showtext包使用 Google Fonts ,就像我下面的例子一样,但这仅适用于数字:

---
title: "Title"
output:
  pdf_document
---

# Header One  

## Header Two
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure …
Run Code Online (Sandbox Code Playgroud)

r r-markdown showtext

3
推荐指数
1
解决办法
907
查看次数