我想用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) })
如果我使用geom_roster:
p <- ggplot(melt(coincidences), aes(Var1,Var2, fill=value)) + geom_raster()
答案 0 :(得分:8)
您应该使用scale_fill_continuous(guide = FALSE)
删除图例。然后,为了摆脱所有填充(轴,标签等),您可以使用这个长theme()
命令:
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())