如何在绘图中将希腊字母添加到 3D 绘图的轴标签?

问题描述 投票:0回答:1

我使用

plotly

绘制了下面的图
library(plotly)
set.seed(1)
n <- 100
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)


base<-'B1'
compare<-'A1'

p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
  layout(
    title = "Some plot",
    scene = list(
      yaxis = list(title = expression('theta'))
    ))
p

我想在 y 轴标题中添加希腊表达式

theta
,并尝试使用
expression(theta)
,但它没有渲染。

您能找到如何在

plotly
中添加希腊字母吗?

r plot plotly
1个回答
0
投票

一种选择是使用 UTF-8 代码,例如

"\u03B8"
代表θ

library(plotly)
set.seed(1)

n <- 100
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)

base<-'B1'
compare<-'A1'

p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
  layout(
    title = "Some plot",
    scene = list(
      xaxis = list(title = list(text = "\u03B8")),
      yaxis = list(title = "Y-axis")
    ))
p

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.