【问题标题】:How to plot a greek letter on a 3D plot label with hist3D()?如何使用 hist3D() 在 3D 绘图标签上绘制希腊字母?
【发布时间】:2013-12-13 09:54:41
【问题描述】:

我正在使用 hist3D() 绘制一个 3D 直方图,并且想要更改 xlab 以便它包含一个带下标的希腊字母。

我用过

xlab=expression(theta[1]). 

它不起作用,我只是在标签中得到字符串“theta[1]”。另一方面,它只适用于常规的绘图命令。

那么如何在hist3D() plots 中引入下标希腊字母呢?

hist3D() 在 plot3D 库中)

【问题讨论】:

  • 您应该添加一个可重现的示例并说明您使用的是哪个包。
  • 函数hist3D调用函数persp。来自?persp,有关xlabThese must be character strings; expressions are not accepted.
  • 感谢@SvenHohenstein

标签: r plot3d


【解决方案1】:

另一种解决方法是使用同一 plot3D 包中的 text3D 函数。它接受数学表达式作为标签,所以我们可以像往常一样写expression(theta[1])。此解决方法中唯一的小问题是找到我们标签的合适坐标

# example data
library(plot3D)
x <- seq(-pi, pi, by = 0.2)
y <- seq(-pi, pi, by = 0.3)
grid <- mesh(x, y)
z <- with(grid, cos(x) * sin(y))

hist3D(z = z, x = x, y = y, border = "black", ticktype = "detailed", xlab = "", ylab="y", zlab="z")
text3D(2, -5, 0, labels = expression(theta[1]), add = TRUE, adj = 1)

我发现2,-5,0 非常适合这个例子。标签不会像常规标签那样旋转一圈。

【讨论】:

    【解决方案2】:

    hist3D函数不接受轴标签的表达式。一种解决方法是使用 Unicode 字符作为 theta,θ。

    # example data
    library(plot3D)
    x <- seq(-pi, pi, by = 0.2)
    y <- seq(-pi, pi, by = 0.3)
    grid <- mesh(x, y)
    z <- with(grid, cos(x) * sin(y))
    
    hist3D(z = z, x = x, y = y, border = "black", xlab = "θ1")
    

    这会显示一个 theta 符号,但没有下标 1。

    【讨论】:

      【解决方案3】:

      解决方法是使用scatterplot3d:

      z <- seq(-10, 10, 0.01)
      x <- cos(z)+1
      y <- sin(z)+1
      scatterplot3d(volcano, highlight.3d=TRUE, col.axis="blue",
                                  col.grid="gray", main="scatterplot-greeks", pch=21,
                                  xlab=expression(theta[1]),
                                  ylab=expression(beta[2]),
                                  zlab=expression(alpha[3]),cex.lab=1.5)
      

      【讨论】:

      • 我更喜欢 persp,它绘制的东西比这更好......但是谢谢。
      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 2017-07-22
      • 2014-11-10
      • 1970-01-01
      相关资源
      最近更新 更多