I am trying to apply geom_tile or heatmap indistinctly, but the results when I apply them are completely different.
I think that I understand why, I think that it is because the units for the different variable are different between them. So, while heatmap function understands that and only compares whit the same variable in the same column, geom_tile requires that all the variables including into the dataset will be expressed in the same unit.
1) Am I wrong with my assumption? 2) There is a way to use geom_tile and obtain the same result generated by heatmap?
Example using heatmap function:
library(ggplot2)
library(RColorBrewer)
library(readr)
url_soccer <- 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_Matrix_heatmap.csv'
df_matrix <- read_csv(url_soccer)
# Order data for titles
df_matrix <- df_matrix[order(df_matrix$Titles, decreasing = FALSE),]
df_matrix <- data.frame(df_matrix)
#removing names of the teams.
row.names(df_matrix) <- df_matrix$Team
df_matrix <- df_matrix[,-1]
options(digits=2)
df_matrix$Points_1 <- sub(',', '.', df_matrix$Points_1)
df_matrix$Points_1 <- as.double(df_matrix$Points_1)
# transformation to numeric for column "Performance"
df_matrix$Performance =
substr(df_matrix$Performance,1,nchar(df_matrix$Performance)-1)
df_matrix$Performance <- sub(',', '.', df_matrix$Performance)
df_matrix$Performance <- as.double(df_matrix$Performance)
df_matrix$Performance <- log(df_matrix$Performance)
small_matrix <- data.matrix(df_matrix)
# Creation of heatmap
america_heatmap <- heatmap(small_matrix, Rowv=NA,
Colv=NA, col = brewer.pal(9, "Blues"),
scale="column",
margins=c(2,6))
Example using geom_tile function:
url_soccer 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_format_ggplot_geom_tile.csv'
df_exa <- read_csv(url_soccer)
ggplot(data = df_exa, aes(x = df_exa$country, y = df_exa$metric)) +
geom_tile(aes(fill = df_exa$value)) +
coord_flip()+
theme_minimal()