【问题标题】:HTML greek letters with ggplotly带有 ggplotly 的 HTML 希腊字母
【发布时间】:2016-10-24 17:08:08
【问题描述】:

当使用ggplotly 将 ggplot 图形转换为 plotly 图形时,我可以获得一些 HTML,例如在标题中:

library(plotly)
library(ggplot2)
library(scales)

library(mvtnorm)
sims <- rmvnorm(500, mean=c(0,0,0))
dat <- setNames(data.frame(sims), c("x", "y", "z"))
dat$z <- dat$x+dat$y

gg <- ggplot(dat, aes(x=x, y=y, colour=z)) + 
  geom_point() + 
  scale_colour_gradient2(limits=c(-2,2), midpoint=0, low=muted("blue"), high=muted("red")) + 
  ggtitle("<em>hello</em>")

ggplotly(gg)

正如预期的那样,标题&lt;em&gt;hello&lt;/em&gt; 以斜体显示。

但是当我想要一个 HTML 希腊字母时,这不起作用:

gg <- ggplot(dat, aes(x=x, y=y, colour=z)) + 
  geom_point() + 
  scale_colour_gradient2(limits=c(-2,2), midpoint=0, low=muted("blue"), high=muted("red")) + 
  ggtitle("&Delta;")

ggplotly(gg)

如何将&amp;Delta; 渲染为预期的希腊字母?

我正在使用plotly_4.5.2ggplot2_2.1.0

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

    这适用于decimal character reference

    gg <- ggplot(dat, aes(x=x, y=y, colour=z)) + 
      geom_point() + 
      scale_colour_gradient2(limits=c(-2,2), midpoint=0, low=muted("blue"), high=muted("red")) + 
      ggtitle("&#916;")
    ggplotly(gg)
    

    根据this comment on the Github repoplotly.js 最近去掉了泛化的 HTML 实体解码”。我不太明白,但可能是解释。

    2017 年 8 月 25 日更新

    plotly 开发人员现在已经删除了 html 十进制字符编码。作为一种解决方案,可以直接输入一个UTF-8字符,或者使用intToUtf8

    ggtitle("Δ")
    ggtitle(intToUtf8(0x0394L))
    

    【讨论】:

    • 好!你是在自问自答。我会删除我的。您可以接受自己的答案,以便其他人知道
    • @user 是的,但两天前不能接受自己的答案。
    猜你喜欢
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 2021-07-02
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多