Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating a heatmap in R

I am trying to create a heatmap of the following plot. Whenever i use the heatmap function instead of geom_point, I get this error:

"Error in heatmap(Wizard_heatmap, aes(x = Gate)) : 'x' must be a numeric matrix"

Dataframe

Wizard_heatmap <- structure(list(Response = c("LIZARD", "LIZARD", "LIZARD", "NR", 
                                              "NR", "WAITER", "WEEKEND", "WHALE", "WHEELCHAIR", "WHIP", "WHISKEY", 
                                              "WHISTLE", "WHISTLE", "WHISTLE", "WIND", "WINDMILL", "WINDOW", 
                                              "WINDOW", "WINTER", "WISDOM", "WISDOM", "WIZARD", "WIZARD", "WIZARD", 
                                              "WIZARD", "WOMEN", "WOOD", "WOODCHIP"), 
                                 Target = c("WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", 
                                            "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", 
                                            "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD",
                                            "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD", "WIZARD"), 
                                 Gate = c("Full", "Gate 2", "Gate 3", "Gate 0", "Gate 1", 
                                          "Gate 0", "Gate 1", "Gate 0", "Gate 0", "Gate 0", "Gate 1", 
                                          "Gate 0", "Gate 1", "Gate 2", "Gate 0", "Gate 0", "Gate 0", 
                                          "Gate 1", "Gate 0", "Gate 1", "Gate 2", "Full", "Gate 1", 
                                          "Gate 2", "Gate 3", "Gate 0", "Gate 0", "Gate 0"), 
                                 n = c(1,  2, 2, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 7,
                                       1, 15, 1, 12, 14, 1, 1, 1)), row.names = c(NA, -28L), class = c("tbl_df", "tbl", "data.frame"))

Simple plot

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ggplot(Wizard_heatmap, aes(x = Gate)) +
    geom_point(aes(y = Response), size = 4, color = "red")+
    xlab("Gate")

This is for an error analysis, and we are trying to see where errors are concentrated. We also want to get a sense of where the errors are occurring, so that is why the x axis is sorted by gate. Lastly, in the df, you will see one of the columns is labelled "n". larger "n" should be darker on the heatmap. Thanks in advance!

>Solution :

If you want a heatmap with this dataset you could do:

heatmap(with(Wizard_heatmap, as.matrix(table(factor(Response), factor(Gate)))))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading