I want to plot, with ggplot2, a confusion matrix like this:
# 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:
How can I get this? (no legends, no padding)
You should use scale_fill_continuous(guide = FALSE)
to remove the legend. Then to get rid of all the padding (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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With