这有点棘手,但下面的函数可以帮您完成。它是基于
mtext3d
在
rgl
library(plot3D)
library(latex2exp)
mtext3D <- function(text, edge, line = 0, at = NULL, pos = NA, ranges, trans,
adj = c(0.5, 0.5), ...)
{
edge <- c(strsplit(edge, '')[[1]], '-', '-')[1:3]
coord <- match(toupper(edge[1]), c('X', 'Y', 'Z'))
# Put the sign in the appropriate entry of edge
if (coord == 2) edge[1] <- edge[2]
else if (coord == 3) edge[1:2] <- edge[2:3]
range <- ranges[[coord]]
if (is.null(at)) at <- mean(range)
newlen <- max(length(text),length(line),length(at))
text <- rep(text, len = newlen)
line <- rep(line, len = newlen)
at <- rep(at, len = newlen)
if (all(is.na(pos))) {
pos <- matrix(NA,3,length(at))
if (edge[1] == '+') pos[1,] <- ranges$x[2]
else pos[1,] <- ranges$x[1]
if (edge[2] == '+') pos[2,] <- ranges$y[2]
else pos[2,] <- ranges$y[1]
if (edge[3] == '+') pos[3,] <- ranges$z[2]
else pos[3,] <- ranges$z[1]
}
else pos <- matrix(pos,3,length(at))
pos[coord,] <- at
ticksize <- 0.05*(pos[,1]-c(mean(ranges$x),mean(ranges$y),mean(ranges$z)))
ticksize[coord] <- 0
# Find rotation corresponding to box edge
direction <- pos[, c(1,1), drop = FALSE]
direction[coord, ] <- range
xy <- trans3d(x = direction[1,], y = direction[2,], z = direction[3,], pmat = trans)
srt <- atan2(diff(xy$y), diff(xy$x))
# Adjust rotation so text goes from left to right
if (cos(srt) < 0) srt <- srt + pi
text(trans3d(x = pos[1,]+3*ticksize[1]*line,
y = pos[2,]+3*ticksize[2]*line,
z = pos[3,]+3*ticksize[3]*line, trans),
text, srt = srt * 180/pi, xpd = NA, ...)
}
test <- matrix(runif(100), ncol = 10)
par(mar = c(10, 10, 10, 10)/2)
trans <- hist3D(z = test, bty = "g", phi = 15, theta = -15,
xlab = "", ylab = "",
zlab = "Frequency", main = "",
col = "white", border = "black", shade = NULL, curtain = T, plot = T,
ticktype = "detailed", space = 0.15, d = 2, cex.axis = 1e-9, image = T, contour = T)
ranges <- list(x = 0:1, y = 0:1, z = range(test))
mtext3D(TeX("Polygonal vertices $(\\xi_1)$"), "x--", line = 1.5, ranges = ranges, trans = trans)
mtext3D(TeX("Polygonal vertices $(\\xi_2)$"), "y--", line = 1.5, ranges = ranges, trans = trans)
mtext3D
添加标签。它们可以包含希腊语或其他特殊字符,就像其他基本情节一样。以上示例的结果如下: