How to change the `heatmaply_cor` correlation heatmap y-label to not be row numbers?

I am trying to make a heatmap for a correlation matrix. I would like the y and x axis labels to be according to variable. For example, in the square comparing total_sales correlation with penetration I would like it to say either penetration and total_sales on each axis. For some reason, the examples online have their y-axis labeled according to variable but mine is by row number. I've put a reproducible example below.

df_try <- data.frame(term = c("total_sales", "penetration", "Density"),
                        total_sales = c(NA, .75, .34),
                        penetration = c(.65, NA, .88),
                        Density = c(-.24, -.55, NA))
heatmaply_cor(
  df_try,
  xlab = "Features", 
  ylab = "Features",
  k_col = 2, 
  k_row = 2
)

The heatmap has 2, 1, 3 on the y axis and Density, penetration, total_sales on the x axis. I do not want it to say 2, 1, 3, I would like it to say penetration, total_sales, Density.

That is because (even in the examples), it is the row names that are used as y labels. In your case, that can be solved simply with using term as row names instead of a separate column:

df_try <- data.frame(row.names = c("total_sales", "penetration", "Density"),
                     total_sales = c(NA, .75, .34),
                     penetration = c(.65, NA, .88),
                     Density = c(-.24, -.55, NA))

If you're used to the tidyverse, you might like column_to_rownames() that does this transformation on an existing tibble.

Thank you - that did the trick! Appreciate it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.