You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ggplot中使用ggtext渲染HTML符号✽不显示的解决方法咨询

解决ggtext中HTML实体不显示的问题

你的代码里HTML实体✽未显示的核心原因是错误转义了&符号:你写的✽会被ggtext解析为普通文本✽,而非对应的对勾符号。以下是两种可行的解决方法:

方法1:直接使用Unicode字符

ggtext支持直接输入Unicode符号,你可以把HTML实体替换为对应的对勾字符✓:

ggplot(df) +
  aes(
    x, y, label = label, angle = angle, color = color,
    hjust = hjust, vjust = vjust
  ) +
  geom_point(color = "black", size = 2) +
  scale_color_identity() +
  xlim(0, 1) + ylim(0, 1) + 
  annotate(
    geom = 'richtext', angle = 90, vjust = .5, hjust = .5, color = "black", label.colour = NA, fill = NA, 
    label = "<span style = 'font-size: 20px'>HTML Sign : ✓</span>",
    x = 0.50,
    y = 0.50
  )

方法2:正确使用HTML实体(不转义&)

去掉对&符号的转义,直接使用&#10045;即可让ggtext正确解析实体:

ggplot(df) +
  aes(
    x, y, label = label, angle = angle, color = color,
    hjust = hjust, vjust = vjust
  ) +
  geom_point(color = "black", size = 2) +
  scale_color_identity() +
  xlim(0, 1) + ylim(0, 1) + 
  annotate(
    geom = 'richtext', angle = 90, vjust = .5, hjust = .5, color = "black", label.colour = NA, fill = NA, 
    label = "<span style = 'font-size: 20px'>HTML Sign : &#10045;</span>",
    x = 0.50,
    y = 0.50
  )

注:代码中已将未定义的Plot_Text_Color替换为"black",避免运行报错。

内容的提问来源于stack exchange,提问作者Brian Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 22:33:16