我想使用bioconductor的hexbin(我可以做)来生成一个填充整个(png)显示区域的图 - 没有轴,没有标签,没有背景,没有nuthin' .
根据我在Chase的回答中的评论,你可以使用 element_blank 删除很多这样的东西:
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的边缘周围仍然有一个小的余量 . 也许其他人知道如何删除该组件 .
(历史记录:自 ggplot2 版本0.9.2以来, opts 已被弃用 . 请使用 theme() 并将 theme_blank() 替换为 element_blank() . )
opts
theme()
theme_blank()
element_blank()
Re:将opts更改为主题等(对于懒人):
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())
'opts' is deprecated.
在 ggplot2 >= 0.9.2 使用
ggplot2 >= 0.9.2
p + theme(legend.position = "none")
目前的答案不完整或效率低下 . 这是(也许)实现结果的最短途径(使用 theme_void() :
theme_void()
data(diamonds) # Data example ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + theme_void() + theme(legend.position="none")
结果是:
如果你对消除 labels 感兴趣, labs(x="", y="") 可以解决问题:
labs(x="", y="")
ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + labs(x="", y="")
xy <- data.frame(x=1:10, y=10:1) plot <- ggplot(data = xy)+geom_point(aes(x = x, y = y)) plot panel = grid.get("panel-3-3") grid.newpage() pushViewport(viewport(w=1, h=1, name="layout")) pushViewport(viewport(w=1, h=1, name="panel-3-3")) upViewport(1) upViewport(1) grid.draw(panel)
这样做你想要的吗?
p <- ggplot(myData, aes(foo, bar)) + geom_whateverGeomYouWant(more = options) + p + scale_x_continuous(expand=c(0,0)) + scale_y_continuous(expand=c(0,0)) + opts(legend.position = "none")
6 回答
根据我在Chase的回答中的评论,你可以使用
element_blank
删除很多这样的东西:当我保存时,看起来在得到的.png的边缘周围仍然有一个小的余量 . 也许其他人知道如何删除该组件 .
(历史记录:自 ggplot2 版本0.9.2以来,
opts
已被弃用 . 请使用theme()
并将theme_blank()
替换为element_blank()
. )Re:将opts更改为主题等(对于懒人):
在
ggplot2 >= 0.9.2
使用目前的答案不完整或效率低下 . 这是(也许)实现结果的最短途径(使用
theme_void()
:结果是:
如果你对消除 labels 感兴趣,
labs(x="", y="")
可以解决问题:这样做你想要的吗?