Error in function to create heatmap using ggplot2

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Error in function to create heatmap using ggplot2



I'm trying to make a heatmap using ggplot2. What I want to be plotted is in the form of a matrix which is the result of a function.



Here is the data:



enter image description here



Here is the function:


vector_a <- names(master)[2:4]
vector_b <- names(master)[5:6]

heatmap_prep <- function(dataframe, vector_a,vector_b){
dummy <- as.data.frame(matrix(0, nrow=length(vector_a), ncol=length(vector_b)))
for (i in 1:length(vector_a)){
first_value <- dataframe[[ vector_a[i] ]]
# print(first_value)
for(j in 1:length(vector_b)){
second_value <- dataframe[[ vector_b[j] ]]
result <- cor(first_value, second_value, method = "spearman")
dummy [i,j] <- result
}
}

rownames(dummy) <- vector_a
return(as.matrix(dummy))
heatmap_data_matrix1 <- heatmap_prep(master,vector_a, vector_b)



Using the data in heatmap_data_matrix1, I want to create a heatmap using the following code:


if (length(grep("ggplot2", (.packages() ))) == 0){
library(ggplot2)
}

p <- ggplot(data = heatmap_data_matrix1, aes(x = vector_a, y = vector_b)
+ geom_tile(aes(fill = ))



However, this does not work. How should I reformat my data/code so this heatmap can be created?



Thanks!





Please share your data in a reproducible format. Pictures of data are not particularly helpful.
– MrFlick
4 secs ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Regex - How to capture all iterations of a repeating pattern?