没有轴、图例等的 ggplot2 图 [英] ggplot2 plot without axes, legends, etc
问题描述
我想使用 bioconductor 的 hexbin(我可以这样做)生成一个填充整个 (png) 显示区域的图 - 没有轴、没有标签、没有背景、没有 nuthin'.
I want to use bioconductor's hexbin (which I can do) to generate a plot that fills the entire (png) display region - no axes, no labels, no background, no nuthin'.
推荐答案
根据我在 Chase 的回答中的评论,您可以使用 element_blank
删除很多这样的东西:
As per my comment in Chase's answer, you can remove a lot of this stuff using element_blank
:
dat <- data.frame(x=runif(10),y=runif(10))
p <- ggplot(dat, aes(x=x, y=y)) +
geom_point() +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0))
p + theme(axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),legend.position="none",
panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),plot.background=element_blank())
当我保存它时,结果 .png 的边缘看起来仍然有一小部分空白.也许其他人甚至知道如何删除该组件.
It looks like there's still a small margin around the edge of the resulting .png when I save this. Perhaps someone else knows how to remove even that component.
(历史记录:从 ggplot2 0.9.2 版开始,opts
已被弃用.改为使用 theme()
并替换 theme_blank()
和 element_blank()
.)
(Historical note: Since ggplot2 version 0.9.2, opts
has been deprecated. Instead use theme()
and replace theme_blank()
with element_blank()
.)
这篇关于没有轴、图例等的 ggplot2 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!