作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以将部分斜体文本标签传递到 ggplot 中?我尝试过使用 expression
和 italic
命令 (expression(paste(italic("some text")))
),但这些不能传递到数据帧中,因为命令的结果不是原子的。设置参数 fontface = "italic"
也不够,因为这会使整个标签变成斜体,而不仅仅是标签中选定的一组字符。例如,我希望一些必须斜体的拉丁短语在标签中以斜体显示(例如“in vivo point”中的“in vivo”)。
library(ggplot)
library(ggrepel)
df <- data.frame(V1 = c(1,2), V2 = c(2,4), V3 = c("in vivo point","another point"))
ggplot(data = df, aes(x = V1, y = V2)) + geom_point() + geom_text_repel(aes(label = V3))
最佳答案
您可以使用 parse = TRUE
将 ?plotmath
表达式(作为字符串)传递给 geom_text
或 geom_text_repel
。您必须将字符串重写为绘图,但如果不是太多,也还不错。
df <- data.frame(V1 = c(1,2), V2 = c(2,4),
V3 = c("italic('in vivo')~point", "another~point"))
ggplot(data = df, aes(x = V1, y = V2, label = V3)) +
geom_point() +
geom_text_repel(parse = TRUE)
关于r - 如何在 ggplot 的 geom_text_repel 或 geom_text 标签中包含斜体文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528953/
我是一名优秀的程序员,十分优秀!