用R / plotly在轴标题中写入摄氏度

Lik*_*iky 1 r plotly

我正在尝试在我的标题之一中用R / Plotly写出摄氏度符号。当我仅使用下面的简单绘图时,它就可以工作:

# Working code
library(latex2exp)
set.seed(1)  
betas <- rnorm(1000)
hist(betas, main = TeX("Temperature (^0C)"))
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试通过代码运行代码时,出现以下错误:“'HashTableSetup'中未实现的类型'expression'。

#Initialise the plot
p <- plot_ly()

#Add axis names
#Font
f <- list(
  family = "Courier New, monospace",
  size = 18,
  color = "#7f7f7f")

#X axis name
x <- list(
  title = "x Axis",
  titlefont = f)


#Y Axis name
y <- list(
  title =  TeX("Temperature (^0C)"),
  titlefont = f)

#Add layout
p <- p %>%
  layout(xaxis = x, yaxis= y)

p
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Lik*_*iky 9

我刚刚找到了一个 hacky 解决方案:在 google 上查找特殊字符,然后将其直接复制并粘贴到 R 代码中。

\n\n
#Y Axis name\ny <- list(\n  title = "Temperature (\xc2\xb0C)",\n  titlefont = f)\n
Run Code Online (Sandbox Code Playgroud)\n\n

我仍然对一种不那么麻烦的解决方案感兴趣,它允许将 LaTeX 插入 Plotly 中。

\n


Lyn*_*akr 6

尝试,

title =  "Temperature (\u00B0C)"
Run Code Online (Sandbox Code Playgroud)


ngh*_*ran 6

尝试title = expression("Temperature ("*~degree*C*")")title = "Temperature (°C)"