如何在带有R的Plotly图中添加带有希腊字母的标题?

问题描述

document.getElementById("id").customFunction();

我在R中有一个 Plotly 直方图,我想添加以下标题。它不一定是标题。只需在图形的空白区域显示文字即可。显然,密谋不接受来自library(plotly) f <- plot_ly(alpha = 0.5) %>% add_histogram(x=rnorm(1000),name="Observed",marker=list(color="darkolivegreen") ) ) f %>% layout(title=expression(theta==0.8%*%hat(theta))) 的{​​{1}},因此上述代码失败。这是帽子部分,这让我真的想将其显示一个适当的等式。会更加清晰。有人可以帮我吗?

equation


我也尝试了this solution,因为Plotly经常从 CSS tutorial)借用。但是,expression()确实会生成粗体文本,而plotmathadd_text(x=10,y=10,text="<b>theta = 0.8*theta_hat</b>")不会生成希腊字母。

解决方法

您可以按照此link的建议使用乳胶。

f <- plot_ly(alpha = 0.5) %>% 
            add_histogram(x=rnorm(1000),name="Observed",marker=list(color="darkolivegreen")
                         )
   
f %>% layout(title=TeX("\\theta = 0.8 \\hat\\theta")) %>% 
      config(mathjax = 'cdn')

enter image description here