ggtext::geom_textbox:如何将链接显示为原始文本?

问题描述 投票:0回答:2

我正在尝试在文本框中显示网络链接(作为原始文本)。但是,出现错误(不幸的是,我不是 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 包于 2021-02-24 创建(v1.0.0)

r ggplot2 escaping ggtext
2个回答
0
投票

我找到了一个非常简单的解决方案。如果您使用 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 包于 2021-02-24 创建(v1.0.0)


0
投票

感谢您的解决方案。 你怎样才能避免用你的方法来签名呢?它不适用于 -

© www.soinside.com 2019 - 2024. All rights reserved.