1

有没有办法修改使用 ggplot2 包中的 geom_tile 生成的热图图例?我想增加图例中的瓷砖数量并在那里设置显示值的最小值和最大值。

在手册页的这个示例中,图例包含五个彩色图块,代表从 -0.4 到 0.4 的值。我怎样才能让例如 9 瓦显示呢?

library (ggplot2)

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(aes(fill=z))
4

1 回答 1

3

我想有几种可能的方法来存档它。一种解决方案是手动指定图例的中断。

d = pp(20)
ggplot(d, aes(x=x,y=y,fill=z)) + geom_tile() + 
    scale_fill_continuous( breaks = round( seq(-.4, .4, length.out = 10 ), 1) )
于 2012-04-15T14:51:33.987 回答