persp() 轴标签中的下标 [英] Subscript in persp() axis label

查看:26
本文介绍了persp() 轴标签中的下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 R 中的 persp() 函数绘制两个变量的函数.这是我目前所拥有的:

I'm trying to plot a function of two variables using the persp()function in R. This is what I have so far:

C_unab <- function(u1, u2) {
  return(u1 * u2)
}

x <- seq(0, 1, by = 0.1)
y <- seq(0, 1, by = 0.1)

z_1 <- outer(x,y, C_unab)

persp(x, y, z_1, theta = -60, phi = 25 ,shade = 0.7,expand = 0.8 , ltheta = -60, ticktype =     "detailed",
      xlab = "u1", ylab = "u2", zlab = "Phi", col="lightblue")

这很好用.但是,我希望轴标签中出现的1"和2"带有下标(即作为索引).我环顾四周,发现了plotmath".然而,这似乎不适用于 pesp() 并且文档说:表达式也可用于标题、副标题和 x 轴和 y 轴标签(但不适用于轴透视图上的标签)."

This works fine. However, I would like the "1" and "2" that appear in the axis labels to be subscripted (i. e. as indices). I've looked around and found "plotmath". However that doesn't seem to work for pesp()and the documentation says:" Expressions can also be used for titles, subtitles and x- and y-axis labels (but not for axis labels on persp plots)."

我也在这附近进行了搜索,但没有找到任何适合我的东西.

I've also done a search around here but haven't found anything that works for me.

任何帮助将不胜感激!

推荐答案

您不能使用带有 persp 的表达式,...这是一个有据可查的限制.通常的建议是切换到格子:

You cannot use expressions with persp, ... a well documented limitation. The usual advice is to switch to lattice:

library(lattice)
png(); print( wireframe(z_1~x+y  ,data=data.frame(x=x, y=rep(y, each=length(x)), z_1=z_1) ,  
                         xlab=expression(u[1]), ylab=expression(u[2]), zlab = "Z") ); dev.off()

这篇关于persp() 轴标签中的下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆