Geom_raster () without padding and no legend

I want to build a confusion matrix with ggplot2 as follows:

# Original data samples <- t(rmultinom(50, size = 7, prob = rep(0.1,10))) # Co-ocurrence matrix coincidences <- sapply(1:ncol(samples), function(i){ colSums(samples[,i]==samples) }) 

If I use geom_roster:

 p <- ggplot(melt(coincidences), aes(Var1,Var2, fill=value)) + geom_raster() 

I get this: enter image description here

How can i get this? (no legends, no extras) enter image description here

+5
source share
1 answer

You must use scale_fill_continuous(guide = FALSE) to remove the legend. Then, to get rid of all the extras (axes, labels, etc.), you can use this long theme() command:

 require(ggplot2) # Original data samples <- t(rmultinom(50, size = 7, prob = rep(0.1,10))) # Co-ocurrence matrix coincidences <- sapply(1:ncol(samples), function(i) { colSums(samples[,i]==samples) }) p <- ggplot(melt(coincidences), aes(Var1, Var2, fill = value)) + geom_raster() + scale_fill_continuous(guide = FALSE) + theme(axis.text = element_blank(), axis.ticks = element_blank(), axis.title = element_blank(), panel.background = element_blank()) 

enter image description here

+7
source

Source: https://habr.com/ru/post/1238634/


All Articles