Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ 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?

A correlation heatmap provides a visual way to examine relationships between numeric variables. By using colors to represent the strength and direction of correlations, it becomes much easier to identify strong or weak associations at a glance. This is particularly helpful when working with many variables, as it can quickly reveal patterns, highlight multicollinearity, and guide further analysis.

Visualizing Correlation Matrix with Heatmap

First, you need to create a correlation matrix for visualization:

# 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")

Then, you can use the ggcorrplot() function to build a plot from it:

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

This function has multiple parameters that can be used to change the style of the plot:

  • 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.
question mark

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

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  6

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 3.  6
some-alt