To align with journal formatting purposes I have been requested to change hyphen (-
, the default as displayed for negative correlations in R
and corrplot
) with a negative sign (−
, U+2212).
I've tried doing this as follows:
library(corrplot)
data(mtcars)
corr_matrix <- cor(mtcars)[1:2, 1:2]
format_coef <- function(coef) {
coef <- sprintf("%.2f", coef) # Round to two dp
coef <- gsub("-", "−", coef) # Replace hyphen with true negative sign
return(coef)
}
# Format coefficients for display
formatted_labels <- apply(corr_matrix, c(1, 2), format_coef)
# Create the correlation plot
corrplot(corr_matrix, method = "circle", type = "full",
tl.col = "black", tl.cex = 0.8,
addCoef.col = NULL, number.cex = 3)
text(rep(1:ncol(corr_matrix), each = nrow(corr_matrix)),
rep(nrow(corr_matrix):1, times = ncol(corr_matrix)),
labels = formatted_labels, cex = 3)
though only the positive correlations are printed with this approach, as shown here:
What am I missing? Is there a better way to do this?