Bob*_*Bob 7 text r ggplot2 plotmath ggrepel
是否可以将部分斜体文本标签传递给ggplot?我尝试使用expression
和italic
commands(expression(paste(italic("some text")))
),但这些不能传递到数据框,因为命令的结果不是原子的.设置参数fontface = "italic"
也不够,因为这会使整个标签斜体化,而不仅仅是标签中的一组选定字符.例如,我想在标签中使用一些斜体字的拉丁短语(例如"体内点"中的"体内").
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))
Run Code Online (Sandbox Code Playgroud)
您可以parse = TRUE
用来将?plotmath
表达式(作为字符串)传递给geom_text
或geom_text_repel
。您必须将字符串重写为plotmath,但是如果不是太多,也还不错。
注意:的CRAN版本ggrepel
有一个会中断的错误parse = TRUE
,但已在GitHub版本上修复。ggplot2::geom_text
工作正常。
# devtools::install_github('slowkow/ggrepel')
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)
Run Code Online (Sandbox Code Playgroud)