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

时间:2015-12-15 11:44:02

标签: r contour axis-labels gplots

这是我可重现的代码示例。除了没有添加轴标题/标签外,所有内容都应该在图表中显示。尽管遵循了功能文档中的说明,我仍然在努力弄清楚如何修复它。非常感谢帮助 - 提前感谢。

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()

1 个答案:

答案 0 :(得分:1)

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

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