在 R 中使用 filled.contour 在 gplot 中添加轴标题

Adding axis titles in gplot using filled.contour in R

这是我可重现的代码示例。图表中的一切看起来都应该如此,除了轴 titles/labels 没有被添加。尽管按照功能文档中的说明进行操作,但我真的很难弄清楚如何修复它。非常感谢您的帮助 - 提前致谢。

output <- matrix(data = c(0.7,0.5,0.3,0.8,0.6,0.4,0.9,0.7,0.5,1,0.8,0.6),nrow=3,
                   ncol=4)

# Change column names
colnames(output) <- c(10,20,30,40)


# Change row names
rownames(output) <- c(1,2,3)

library(gplots)

matrix.axes <- function(data) {
        # Do the rows, las=2 for text perpendicular to the axis
        x <- (1:dim(data)[1] - 1) / (dim(data)[1] - 1);
        axis(side=1, at=x, labels=rownames(data), las=1);
        # Do the columns
        x <- (1:dim(data)[2] - 1) / (dim(data)[2] - 1);
        axis(side=2, at=x, labels=colnames(data), las=2);
}

# Not necessary to save as pdf unless this is part of the problem
# save to pdf
# pdf("C:/Test.pdf")

# Plot results
filled.contour(output,plot.title=title(main="Method"),
                       xlab='Case number',ylab='Sample number',
                       plot.axes=matrix.axes(output))


# dev.off()

您的xlab =ylab =需要plot.title()函数中:

filled.contour(output,
  plot.title = title(main = "Method", xlab='Case number',  ylab='Sample number'),
plot.axes = matrix.axes(output))