使用ggplot的geom_tile()时调整边距 [英] Margin adjustments when using ggplot's geom_tile()
问题描述
从ggplot2的 geom_tile()函数的文档中,我们有如下简单plot: 我如何删除边框的边距?我已经通过抛光剧情脚本挖掘了一些提示,但无济于事。我已经找到了如何使用opts(panel.background = theme_blank())删除背景面板,但不知道如何更改页边空白大小。 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 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:
这篇关于使用ggplot的geom_tile()时调整边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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>
pre $ gent_tile()+
scale_x_continuous(expand = c(0, 0))+
scale_y_continuous(expand = c(0,0))
# 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()
p + geom_tile() +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0))