这个问题在这里已经有了答案:
When using ggplot in R, how do I remove margins surrounding the plot area?
(4 个回答)
5年前关闭。
我想用 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()
我明白了:
我怎样才能得到这个? (无图例,无填充)
最佳答案
您应该使用 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())
关于r - geom_raster() 没有填充和图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34356329/