【问题标题】:Plotting ambient functions with ggplot2用 ggplot2 绘制环境函数
【发布时间】:2021-04-02 09:03:41
【问题描述】:

我在 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)

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

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

但这只是产生了

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

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多