R ggplot2不带轴、图例等的绘图

R ggplot2不带轴、图例等的绘图,r,ggplot2,R,Ggplot2,我想使用bioconductor的hexbin(我可以这么做)生成一个填充整个(png)显示区域的绘图-没有轴,没有标签,没有背景,没有螺母。这是你想要的吗 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(le

我想使用bioconductor的hexbin(我可以这么做)生成一个填充整个(png)显示区域的绘图-没有轴,没有标签,没有背景,没有螺母。

这是你想要的吗

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

p根据我在Chase的回答中的评论,您可以使用
element\u 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())
dat
xy
在
ggplot2>=0.9.2
中使用

p + theme(legend.position = "none") 

回复:将选项更改为主题等(适用于懒人):


目前的答案要么不完整,要么效率低下。下面是(也许)实现结果的最短方法(使用
theme\u void()

结果是:


如果您只想删除标签
labs(x=”,y=”)
的诀窍是:

ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + 
      labs(x="", y="")
派对迟到了,但可能会引起兴趣

我发现
实验室
指南
规范在许多情况下都很有用:

您只需要网格和背景:

ggplot(diamonds, mapping = aes(x = clarity)) + 
  geom_bar(aes(fill = cut)) + 
  labs(x = NULL, y = NULL) + 
  guides(x = "none", y = "none")

您只希望抑制一个或两个轴的记号标签:

ggplot(diamonds, mapping = aes(x = clarity)) + 
  geom_bar(aes(fill = cut)) + 
  guides(x = "none", y = "none")

我在这里找不到此解决方案。它使用cowplot软件包删除所有解决方案:

library(cowplot)

p + theme_nothing() +
theme(legend.position="none") +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0)) +
labs(x = NULL, y = NULL)
刚才注意到,使用theme.void()可以完成同样的事情,如下所示:

p + theme_void() +
theme(legend.position="none") +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0)) +
labs(x = NULL, y = NULL)

创建一个hexbin图并在图像编辑器中进行裁剪不是更容易吗?尝试
theme\u void()
去掉图例,但是x轴和y轴以及背景网格仍然存在。非常感谢!我在评论中也找到了类似的解决方案:在某些情况下,
theme(axis.ticks=element\u blank())
不如
主题(axis.ticks.x=element_blank())
工作,可能是某个地方的临时错误(我有自己的主题集,然后我尝试覆盖:只有
axis.ticks.x
axis.ticks.y
执行此任务。)
使用方法时出错(“grid.draw”):没有适用于“grid.draw”类对象的“grid.draw”方法
grid.ls()显示viewport和grob Objects的列表在我使用的其他版本的ggplot中,面板名称不同XY我意识到您还没有编辑权限,但是如果您发现我的其他ggplot2答案需要更新re:opts()请随意建议编辑。我会收到通知,可以自己合并。
ggplot(data=diamonds,mapping=aes(x=clarity))+geom\u bar(aes(fill=cut))+theme\u void()+theme(legend.position=“none”,panel.background=element\u rect(fill=“grey80”),plot.background=element\u rect(fill=“red”))
表明这不是100%无效。labs(x=”“,y=”“)似乎没有删除轴,只是删除标签。@miratrix抱歉,我的错误。已更新。@luchonacho使用
labs(x=“”,y=“”)
保留轴标题的空格,因为实际上有标题,它们只是没有符号。要删除轴标题和空格,最好使用
+主题(axis.title=element_blank())
labs(x=NULL)
xlab(NULL)
是其他方法。
ggplot(diamonds, mapping = aes(x = clarity)) + 
  geom_bar(aes(fill = cut)) + 
  labs(x = NULL, y = NULL) + 
  guides(x = "none", y = "none")
ggplot(diamonds, mapping = aes(x = clarity)) + 
  geom_bar(aes(fill = cut)) + 
  guides(x = "none", y = "none")
library(cowplot)

p + theme_nothing() +
theme(legend.position="none") +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0)) +
labs(x = NULL, y = NULL)
p + theme_void() +
theme(legend.position="none") +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0)) +
labs(x = NULL, y = NULL)