ggplot2的默认字体是什么 [英] What is the default font for ggplot2

查看:114
本文介绍了ggplot2的默认字体是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中使用ggplot2时,它显然具有base_family字体.它是什么?因为文档仅使用",如...所示.

When using ggplot2 in R, it clearly has a base_family font. What is it? as the documentation just uses "" as can be seen in...

?theme_light()

看起来像ArialMT,但不确定...

It looks like ArialMT but not sure...

推荐答案

这不是一个完整的答案,但其中一些内容如下:

This is not a complete answer, but some of the pieces are as follows:

  • 主题很复杂: http://ggplot2.tidyverse.org/reference/theme.html
  • theme_set()theme_get()可以设置和查询会话的默认主题
  • 主题是列表,名为text的列表及其family元素将告诉您希望使用字体名称.您可以在ggplot中的主题调用中进行设置,以覆盖该主题的默认设置.
  • 在Windows中,windowsFonts()会告诉您字体名称和已安装的系统字体名称之间的映射.我不知道如何在OS X或Linux平台上做到这一点.
  • 在所有平台上,默认值似乎都是serifsansmono.
  • Themes are complicated: http://ggplot2.tidyverse.org/reference/theme.html
  • theme_set() and theme_get() can set and query your default theme for the session
  • A theme is a list, and the named text list and its family element will tell you want font name is being used. You can set that in the theme call in a ggplot to override the default for that theme.
  • In windows the windowsFonts() will tell you the mapping between font names and your installed system font names. I have no idea how to do this in the OS X or Linux platforms though.
  • The default ones seem to be serif, sans, and mono across all platforms.

我的主要开放问题是空白的姓氏"映射到什么,因为这通常是主题中的内容.如果未指定任何内容,则默认设置会以某种方式设置为sans,因为它看起来像这样.

My main open question is what does the blank family name "" map to, since that is usually what is in the themes. If nothing is specified the default somehow gets set to sans, since that it what it seems to be.

我也想不出如何替换theme_gray()中的默认字体系列.认为是时候提问了...

I also couldn't figure out how to replace the default font family in theme_gray(). Think it is time for a question...

> theme_get()$text
List of 10
 $ family    : chr ""
 $ face      : chr "plain"
 $ colour    : chr "black"
 $ size      : num 11
 $ hjust     : num 0.5
 $ vjust     : num 0.5
 $ angle     : num 0
 $ lineheight: num 0.9
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 0 0 0 0
  .. ..- attr(*, "unit")= chr "pt"
  .. ..- attr(*, "valid.unit")= int 8
 $ debug     : logi FALSE
 - attr(*, "class")= chr [1:2] "element_text" "element"

以及Windows中的系统字体映射:

And the system font mapping in windows:

> windowsFonts()
$serif
[1] "TT Times New Roman"

$sans
[1] "TT Arial"

$mono
[1] "TT Courier New"

> 

一个例子:

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(text=element_text(size=16,  family="serif"))

这篇关于ggplot2的默认字体是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆