使用ggplot的geom_tile()时调整边距 [英] Margin adjustments when using ggplot's geom_tile()

查看:784
本文介绍了使用ggplot的geom_tile()时调整边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从ggplot2的 geom_tile()函数的文档中,我们有如下简单plot:
alt text http://had.co.nz/ggplot2/生成数据
pp < - 函数(n,r = 1) 4){
x < - seq(-r * pi,r * pi,len = n)
df < - expand.grid(x = x,y = x)
df $ r < - sqrt(df $ x ^ 2 + df $ y ^ 2)
df $ z <-cos(df $ r ^ 2)* exp(-df $ r / 6)$ b $ (b),b(b),b(b),b(b),b(b),bb(b),bg(b) code>

我如何删除边框的边距?我已经通过抛光剧情脚本挖掘了一些提示,但无济于事。我已经找到了如何使用opts(panel.background = theme_blank())删除背景面板,但不知道如何更改页边空白大小。

解决方案

你可以试试看:

pre $ gent_tile()+
scale_x_continuous(expand = c(0, 0))+
scale_y_continuous(expand = c(0,0))


From the documentation for ggplot2's geom_tile() function, we have the following simple plot: alt text http://had.co.nz/ggplot2/graphics/1dd785939e74fc3e6090dce6bc7f01c6.png

# Generate data 
pp <- function (n,r=4) { 
    x <- seq(-r*pi, r*pi, len=n) 
    df <- expand.grid(x=x, y=x) 
    df$r <- sqrt(df$x^2 + df$y^2) 
    df$z <- cos(df$r^2)*exp(-df$r/6) 
    df 
} 
p <- ggplot(pp(20), aes(x=x,y=y)) 

p + geom_tile()

How do I remove the margins that border the tile? I have dug through this script on polishing plots for some hints to no avail. I have found how to remove the background panels using opts(panel.background=theme_blank()), but not how to change the margin size.

解决方案

Try this:

p + geom_tile() + 
    scale_x_continuous(expand=c(0,0)) + 
    scale_y_continuous(expand=c(0,0))

这篇关于使用ggplot的geom_tile()时调整边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆