gpt4 book ai didi

r - HTML 希腊字母与 ggplotly

转载 作者:行者123 更新时间:2023-12-02 03:23:24 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com