【问题标题】:ggtext::geom_textbox: How to display links as raw text?ggtext::geom_textbox:如何将链接显示为原始文本?
【发布时间】:2021-05-26 15:44:24
【问题描述】:

我正在尝试在文本框中显示 Web 链接(作为原始文本)。但是,得到一个错误(不幸的是,我不是 HTML 专家)。这有什么方法可以重新格式化网络链接,以便它们可以在文本框中显示为原始文本?谢谢!

library(ggtext)
library(ggplot2)

test_data <- data.frame(x = 1,
                        y = 2,
                        text = "https://www.stackoverflow.com") 

ggplot(test_data, aes(x = x, y = y, label = text)) +
  geom_textbox()

#> Error: gridtext has encountered a tag that isn't supported yet: <a>
#> Only a very limited number of tags are currently supported.

reprex package (v1.0.0) 于 2021 年 2 月 24 日创建

【问题讨论】:

标签: r ggplot2 escaping ggtext


【解决方案1】:

我找到了一个非常简单的解决方案。如果您使用 HTML 实体转义相关字符,它就可以工作。

library(ggtext)
library(ggplot2)

test_data <- data.frame(x = 1,
                        y = 2,
                        text = "https:&#47;&#47;www&#46;stackoverflow.com") 

ggplot(test_data, aes(x = x, y = y, label = text)) +
  geom_textbox(width = 0.6)

reprex package (v1.0.0) 于 2021 年 2 月 24 日创建

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2020-09-30
    相关资源
    最近更新 更多