【问题标题】:Using geom_raster function returns invalid 'type' (list) of argument使用 geom_raster 函数返回参数的无效“类型”(列表)
【发布时间】:2018-01-19 11:15:57
【问题描述】:

我正在尝试使用 R 将矩阵数据绘制到 d*d 网格中。所以我使用了geom_raster 函数。

我的数据包含三个变量:row 和 col 指定每个数据点的位置,w 是我希望使用geom_raster 绘制的数据。

我模拟了下面的三个变量:

row <- rep(1:55, 55)
col <- rep(1:55, 55)
w <- runif(55*55)

为了使用ggplot,我将数据转换成dataframe形式:

df <- data.frame(
   row = row, col = col, w = w
)

现在我使用 df 生成绘图

ggplot(data = df, aes(row, col)) + geom_raster(fill = aes(w))

但它返回一个错误提示

stats::complete.cases(df[, vars, drop = FALSE]) 中的错误: 参数的“类型”(列表)无效

我最终不知道如何修复此错误,有人可以帮助我吗?

【问题讨论】:

    标签: r ggplot2 geom-raster


    【解决方案1】:

    geom_raster 的语法看起来不正确。

    试试这个:...

        ggplot(data = df, aes(row, col)) + geom_raster(aes(fill=w))
    

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      相关资源
      最近更新 更多