使用 geom_raster 函数 returns 无效的 'type' (列表)参数
Using geom_raster function returns invalid 'type' (list) of argument
我正在尝试使用 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生成plot
ggplot(data = df, aes(row, col)) + geom_raster(fill = aes(w))
但它 returns 一个错误
Error in stats::complete.cases(df[, vars, drop = FALSE]) :
invalid 'type' (list) of argument
我不知道如何修复这个错误,有人能帮我吗?
您的 geom_raster
的语法看起来不正确。
试试这个:...
ggplot(data = df, aes(row, col)) + geom_raster(aes(fill=w))
我正在尝试使用 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生成plot
ggplot(data = df, aes(row, col)) + geom_raster(fill = aes(w))
但它 returns 一个错误
Error in stats::complete.cases(df[, vars, drop = FALSE]) : invalid 'type' (list) of argument
我不知道如何修复这个错误,有人能帮我吗?
您的 geom_raster
的语法看起来不正确。
试试这个:...
ggplot(data = df, aes(row, col)) + geom_raster(aes(fill=w))