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实体(不转义&)
去掉对&符号的转义,直接使用✽即可让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 : ✽</span>", x = 0.50, y = 0.50 )
注:代码中已将未定义的Plot_Text_Color替换为"black",避免运行报错。
内容的提问来源于stack exchange,提问作者Brian Smith
相关产品推荐
相关产品推荐

