0

我正在尝试使用 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,将数据转换为数据框形式:

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]) 中的错误:参数的“类型”(列表)无效

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

4

1 回答 1

1

您的语法geom_raster看起来不正确。

试试这个:...

    ggplot(data = df, aes(row, col)) + geom_raster(aes(fill=w))
于 2017-08-11T08:04:42.473 回答