当我在ggplot中将字体更改为LM Roman 10时,它会使破折号与字母发生冲突。如何在仍使用此字体的情况下解决此问题?
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message=FALSE,
warning=FALSE
)
library(ggplot2)
library(extrafont)
df <- data.frame(
x = c(1, 1, 2, 2, 1.5),
y = c(1, 2, 1, 2, 1.5),
text = c("bottom-left", "top-left", "bottom-right", "top-right", "label-with-dash")
)
ggplot(df, aes(x, y)) +
geom_text(aes(label = text))
ggplot(df, aes(x, y)) +
geom_text(aes(label = text), family="LM Roman 10")
下面是上面代码的结果:
![](https://i.stack.imgur.com/Jbad1.png)
1条答案
按热度按时间5cg8jx4n1#
通过创建一个函数将破折号替换为unicode破折号来修复它:
然后可以将其应用于图,如: