mihoo
mihoo

Reputation: 157

Adding axis titles in gplot using filled.contour in R

This is my reproducible code example. Everything looks as it should in the graph, except the axis titles/labels are not being added. I am really struggling to figure out how to fix it, despite following the directions in the function documentation. Help will be much appreciated - thanks in advance.

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

Upvotes: 1

Views: 792

Answers (1)

Phil
Phil

Reputation: 4444

Your xlab = and ylab = need to be inside the plot.title() function:

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

Upvotes: 1

Related Questions