Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geom_raster() with no padding and no legend [duplicate]

Tags:

r

ggplot2

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: enter image description here

How can I get this? (no legends, no padding) enter image description here

like image 392
alberto Avatar asked Dec 18 '15 13:12

alberto


1 Answers

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())

enter image description here

like image 80
maccruiskeen Avatar answered Nov 07 '22 04:11

maccruiskeen