HTML 带有 ggplotly 的希腊字母
HTML greek letters with ggplotly
当使用 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)
标题 <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("Δ")
ggplotly(gg)
如何将 Δ
呈现为预期的希腊字母?
我正在使用 plotly_4.5.2
和 ggplot2_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("Δ")
ggplotly(gg)
根据this comment on the Github repo,plotly.js最近删除了广义HTML实体解码。我不确定是否理解,但它可能是解释。
更新2017-08-25
plotly 开发人员现已删除 html 十进制字符编码。解决方法是直接输入UTF-8字符,或者使用intToUtf8
:
ggtitle("Δ")
ggtitle(intToUtf8(0x0394L))
当使用 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)
标题 <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("Δ")
ggplotly(gg)
如何将 Δ
呈现为预期的希腊字母?
我正在使用 plotly_4.5.2
和 ggplot2_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("Δ")
ggplotly(gg)
根据this comment on the Github repo,plotly.js最近删除了广义HTML实体解码。我不确定是否理解,但它可能是解释。
更新2017-08-25
plotly 开发人员现已删除 html 十进制字符编码。解决方法是直接输入UTF-8字符,或者使用intToUtf8
:
ggtitle("Δ")
ggtitle(intToUtf8(0x0394L))