问题复现
# 导入必要的包
library(ggplot2)
# 设置主题样式
theme_set(theme_minimal(base_size = 15))
# 创建一个简单的折线图
ggplot(data = data.frame(x = c(1, 2, 3), y = c(1, 2, 3)), aes(x = x, y = y)) +
geom_line(color = "blue") +
labs(title = "欢迎关注公众号:pythonic生物人", color = "red") +
theme(plot.title = element_text(hjust = 0.5, color = "red"),
axis.text = element_text(color = "black"))
使用R绘图时,当涉及到中文字体时,常常出现上图中的“豆腐块”,下文介绍一种超级简单解决方法。
问题解决
# 导入必要的包
library(ggplot2)
library(showtext)
showtext_auto()
# 设置主题样式
theme_set(theme_minimal(base_size = 15))
# 创建一个简单的折线图
ggplot(data = data.frame(x = c(1