Q:

Change the axis marks using plot.matrix

I have a matrix that I would like to plot as a heat map in R, using the plot.matrix package. My matrix is 80 x 80, but I would only like to plot the entries in every fifth row and column (so a 16 x 16 non-contiguous submatrix). However, I would still like the x and y axis marks to be 5, 10, 15, etc. rather than 1, 2, 3, etc., which I have not been able to figure out. Below is my code (the matrix is called MSE):
byfive = seq(from = 5, to = 80, by = 5)
par(mar=c(5.1, 4.1, 4.1, 4.1)) 
plot(MSE[byfive, byfive], xlab = "m2", ylab = "m1", main = "Mean-squared error")

and here is the output:

I would like for the axis marks to be 5, 10, 15, etc. rather than 1, 2, 3, etc. If anyone knows how to fix this, or if anyone knows another package that can do this easily, I would greatly appreciate it. 

A:

As you are new around, it is always good to include a reproducible example of your data, that way is easier for us to answer.  
To get it done, you just have to add byfive as row and col names to your matrix.

# Vector 80 * 80
mse <- runif(80 * 80, min = 10, max = 14)
# dimentions to matrix
dim(mse) <- c(80, 80)

# index to plot
byfive = seq(from = 5, to = 80, by = 5)

# New matrix keeping elements to plot
mse2 <- mse[byfive, byfive]

# adding row and col names
colnames(mse2) <- byfive
rownames(mse2) <- byfive

# plot
plot(mse2, xlab = "m2", ylab = "m1", main = "Mean-squared error")

Using tidyverse:

library(ggplot2)
library(dplyr)
library(tidyr)
library(forcats)

mse2 %>% 
    as.data.frame() %>% 
    rownames_to_column(var = "m1") %>% 
    tidyr::pivot_longer(
        cols = -m1,
        names_to = "m2",
        values_to = "mse"
    ) %>% 
    ggplot(aes(x = fct_inorder(m2), y = fct_inorder(m1), fill = mse)) +
    geom_tile() +
    theme_minimal() +
    scale_fill_viridis_c() +
    labs(x = "m2", y = "m1",
         title = "Mean-squared error") +
    theme(legend.position = "bottom",
          axis.ticks = element_line(color = 'black'))

