R 修改plot字体为times new roman
时间: 2024-02-13 08:04:11 浏览: 43
你可以使用以下代码将R中plot的字体修改为times new roman:
```R
# 安装 times new roman 字体
# 安装 extrafont 包
install.packages("extrafont")
# 导入 times new roman 字体
library(extrafont)
font_import(pattern = "times new roman")
# 修改 plot 字体为 times new roman
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
theme(text = element_text(family = "Times New Roman"))
```
首先,你需要安装`extrafont`包并导入`times new roman`字体。然后,使用`ggplot2`包绘制图形,并使用`theme`函数将字体设置为`Times New Roman`。
相关问题
R plot 字体times new roman
要在R中使用Times New Roman字体,可以使用以下代码:
```r
# 安装extrafont包
install.packages("extrafont")
# 加载extrafont包
library(extrafont)
# 导入Times New Roman字体
font_import(pattern = "times new roman")
# 指定字体为Times New Roman
windowsFonts(
"Times New Roman" = windowsFont("Times New Roman")
)
# 绘图
plot(1:10,
main = "Example Plot",
xlab = "X-axis label",
ylab = "Y-axis label",
family = "Times New Roman")
```
这里我们通过extrafont包来导入Times New Roman字体,并使用windowsFonts()函数来指定字体。在绘图时,通过family参数来指定使用的字体。
R语言中plot画图设置字体为Times New Romance
可以使用R语言中的`par`函数来设置字体。具体来说,可以使用`family`参数指定字体名称。以下是将字体设置为"Times New Roman"的示例代码:
```r
# 设置字体为Times New Roman
par(family = "Times New Roman")
# 绘制散点图
plot(x, y)
```
其中,`x`和`y`是要绘制的散点图的数据。通过这种方式设置字体后,绘制的图形中的文字就会使用指定的字体。