r - HTML 希腊字母与 ggplotly

标签 r ggplot2 plotly

使用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)

enter image description here

标题<em>hello</em>正如预期的那样,以斜体显示。

但是当我想要一个 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)

enter image description here

如何渲染 &Delta;正如预期的希腊字母?

我正在使用plotly_4.5.2ggplot2_2.1.0 .

最佳答案

这适用于 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-08-25

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

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

关于r - HTML 希腊字母与 ggplotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40223815/

相关文章:

linux - 如何在没有 root 权限的情况下安装 Bioconductor 软件包?

r - 在 R 中,有没有办法根据一系列数字为渐变上的绘图点着色?

r - ggplot coord_polar() 在 pi/2 和 -pi/2 之间绘制顶部和底部

python - 如何有效地绘制大量线形,其中点两两相连?

r - 如何将多条迹线添加到单个图中?

r - 使用 r 将两个变量的值组合在一起以创建一个新变量

r - 删除功能使其停止在R中的元素

r - 根据位置放置字符

r - 在ggplot2中用y轴值附加%符号

python - 是否可以构建一个具有过滤数据框的下拉菜单的绘图图?