Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Visualizing Correlations with Heatmaps | Basic Statistical Analysis
Data Analysis with R

bookVisualizing Correlations with Heatmaps

Correlation matrices can be overwhelming to interpret just by looking at numbers. Heatmaps provide a visual way to see the strength and direction of relationships between variables.

Why Use a Correlation Heatmap?

  • Makes it easier to spot strong or weak correlations visually;
  • Helps identify multicollinearity in your data;
  • Uses color to communicate positive, negative, or neutral relationships;
  • Especially useful when dealing with many numeric variables.

Creating the Correlation Matrix

# Select numeric columns
numeric_df <- df[, c("selling_price", "km_driven", "max_power", "mileage", "engine")]
# Compute correlation matrix
cor_matrix <- cor(numeric_df, use = "complete.obs")
View(cor_matrix)

Visualizing with ggcorrplot

ggcorrplot(cor_matrix, 
           method = "square", 
           type = "full", 
           lab = TRUE, 
           lab_size = 5, 
           colors = c("red", "white", "forestgreen"),
           title = "Correlation Heatmap",
           ggtheme = ggplot2::theme_light())

  • method = "square" makes each cell a square block;
  • lab = TRUE overlays the correlation values on each block;
  • colors indicate direction: red (negative), white (neutral), green (positive);
  • theme_light() gives the plot a clean, minimal style

Summary

  • Use cor() to calculate relationships, and ggcorrplot() to visualize them;

  • Color-coded matrices help you quickly grasp complex correlation patterns;

  • Always clean and convert your numeric columns before running correlation analysis.

question mark

Which function from the ggcorrplot package is used to visualize correlations?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 6

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain how to interpret the colors in the heatmap?

What should I do if my dataset has missing values?

How can I customize the appearance of the heatmap further?

Awesome!

Completion rate improved to 4

bookVisualizing Correlations with Heatmaps

Desliza para mostrar el menú

Correlation matrices can be overwhelming to interpret just by looking at numbers. Heatmaps provide a visual way to see the strength and direction of relationships between variables.

Why Use a Correlation Heatmap?

  • Makes it easier to spot strong or weak correlations visually;
  • Helps identify multicollinearity in your data;
  • Uses color to communicate positive, negative, or neutral relationships;
  • Especially useful when dealing with many numeric variables.

Creating the Correlation Matrix

# Select numeric columns
numeric_df <- df[, c("selling_price", "km_driven", "max_power", "mileage", "engine")]
# Compute correlation matrix
cor_matrix <- cor(numeric_df, use = "complete.obs")
View(cor_matrix)

Visualizing with ggcorrplot

ggcorrplot(cor_matrix, 
           method = "square", 
           type = "full", 
           lab = TRUE, 
           lab_size = 5, 
           colors = c("red", "white", "forestgreen"),
           title = "Correlation Heatmap",
           ggtheme = ggplot2::theme_light())

  • method = "square" makes each cell a square block;
  • lab = TRUE overlays the correlation values on each block;
  • colors indicate direction: red (negative), white (neutral), green (positive);
  • theme_light() gives the plot a clean, minimal style

Summary

  • Use cor() to calculate relationships, and ggcorrplot() to visualize them;

  • Color-coded matrices help you quickly grasp complex correlation patterns;

  • Always clean and convert your numeric columns before running correlation analysis.

question mark

Which function from the ggcorrplot package is used to visualize correlations?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 6
some-alt