Paul
Paul

Reputation: 323

Using geom_raster function returns invalid 'type' (list) of argument

I am trying to plot a matrix data into d*d grid using R. So I used geom_raster function.

I have data with three variables: row and col specify the location for each data point, and w is the data I wish to plot using geom_raster.

I simulate the three variables below:

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

I order to use ggplot, I convert the data into dataframe form:

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

Now I use df to generate plot

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

But it returns an error that says

Error in stats::complete.cases(df[, vars, drop = FALSE]) : invalid 'type' (list) of argument

I end up do not know how to fix this bug, would anyone help me out?

Upvotes: 0

Views: 383

Answers (1)

Z.Lin
Z.Lin

Reputation: 29085

The syntax for your geom_raster doesn't look right.

Try this instead:...

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

Upvotes: 1

Related Questions