How do I include italic text in geom_text_repel or geom_text labels for ggplot?

試著忘記壹切 提交于 2019-11-29 07:33:26

You can use parse = TRUE to pass ?plotmath expressions (as strings) to geom_text or geom_text_repel. You'll have to rewrite the strings as plotmath, but if it's not too many it's not too bad.

Note: The CRAN version of ggrepel has a bug that breaks parse = TRUE, but it has been fixed on the GitHub version. ggplot2::geom_text works fine.

# 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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!