Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
ChristianAU
Frequent Visitor

R correlation plot visual

In the uploaded image under the code, I would like the black text marked within the red line to be white.
I'm not sure how to write the code to address this issue.
The code I've used to make the R script visual is:
# Paste or type your script code here:
# Load necessary libraries
library(ggplot2)
library(reshape2)
library(corrplot)

# Ensure that the dataset is not empty
if(nrow(dataset) > 0) {
    # Compute the correlation matrix
    cor_matrix <- cor(dataset, use = "complete.obs")
    
    # Increase plot size and adjust margins for better readability
    par(mar = c(4, 4, 2, 2), oma = c(2, 2, 2, 2), mfrow = c(1, 1))
    options(repr.plot.width=10, repr.plot.height=8)
    
    # Define custom color palette
    custom_col <- colorRampPalette(c("#8B0000", "#FFD700", "#006400"))(200)
    
    # Set plot background color and text color
    par(bg = "#003165", col.lab = "white", col.axis = "white", col.main = "white", col.sub = "white")
    
    # Plot the correlation matrix using corrplot with custom settings
    corrplot(cor_matrix, method = "color", type = "upper", 
             tl.col = "white", tl.srt = 45, 
             addCoef.col = "white", number.cex = 0.7,
             col = custom_col)
} else {
    plot.new()
    par(bg = "#003165")
    text(0.5, 0.5, "No data available", cex = 1.5, col = "white")
}
 
ChristianAU_2-1719220009308.png

 

 

 
 
1 REPLY 1
hackcrr
Super User
Super User

Hi, @ChristianAU 

To change the color of the text within the red line to white in your R script visual, you need to adjust the text label color parameters in the corrplot function. Specifically, you need to make sure all text elements in the plot are set to white. Here’s the updated script:

# Load necessary libraries
library(ggplot2)
library(reshape2)
library(corrplot)

# Ensure that the dataset is not empty
if(nrow(dataset) > 0) {
    # Compute the correlation matrix
    cor_matrix <- cor(dataset, use = "complete.obs")
    
    # Increase plot size and adjust margins for better readability
    par(mar = c(4, 4, 2, 2), oma = c(2, 2, 2, 2), mfrow = c(1, 1))
    options(repr.plot.width=10, repr.plot.height=8)
    
    # Define custom color palette
    custom_col <- colorRampPalette(c("#8B0000", "#FFD700", "#006400"))(200)
    
    # Set plot background color and text color
    par(bg = "#003165", col.lab = "white", col.axis = "white", col.main = "white", col.sub = "white")
    
    # Plot the correlation matrix using corrplot with custom settings
    corrplot(cor_matrix, method = "color", type = "upper", 
             tl.col = "white", tl.srt = 45, 
             addCoef.col = "white", number.cex = 0.7,
             col = custom_col,
             cl.cex = 1, cl.col = "white", cl.ratio = 0.2)
} else {
    plot.new()
    par(bg = "#003165")
    text(0.5, 0.5, "No data available", cex = 1.5, col = "white")
}

 

hackcrr

If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.