使用 ggplot2 绘制环境函数

时间:2021-04-02 00:43:32

标签: r ggplot2

我在 R 中使用 ambient 包来生成图表。它提供了一个自定义的基本绘图方法。

library(ambient)
library(dplyr)

grid <- long_grid(x = seq(0, 1, length.out = 1000),
                  y = seq(0, 1, length.out = 1000))

grid <- grid %>% 
  mutate(
    noise = fracture(gen_perlin, fbm, octaves = 4, x = x, y = y, freq_init = 5)
  )

plot(grid, noise)

enter image description here

但是我想使用 ggplot2geom_raster 而不是基础绘图来绘制此图像。我试着做

ggplot(grid, aes(x = x, y = y, color = noise)) +
  geom_raster()

但那只是产生

enter image description here

知道如何用 ggplot2 制作这个吗?

1 个答案:

答案 0 :(得分:2)

错误的审美:光栅绘制一堆相同大小的图块,其中 color 是边框,fill 是图块的颜色。您想要 fill=noise 在这里:

ggplot(grid, aes(x,y, fill=noise)) + geom_raster()

enter image description here