0

I have a [160 x 3] matrix where each column represents the x, y, or z value for each tile of the heat map I am making. I need to store these values so I can run this command in r:

ggplot(data, aes(X, y, fill= Z))   

Thus, I want to create bins for each element and each bin should have the coordinates and value at said position. Filled bins would have objects for ggplot2 to use when coloring tiles.

I tried to iterate this using:

x()*160
y()*160
z()*160
for row in number
for col in number

but I get the error

Error in x() : could not find function "x"

but I don't which package I need or if I am using the correct package.

  • 1
    I'm not sure why are you are trying to iterate here. If you have a matrix, you'll just need to convert that to a data.frame in order to use that with `ggplot`. You can use `as.data.frame()`. Then just pass along the column names to your aesthetics. – MrFlick Oct 27 '21 at 06:11
  • Thank you so much MrFlick. This is actually how I learned to do it but I guess I fell down a rabbit hole. I am so grateful for your comment. Thank you so so so much. – NINA GILSHTEYN Oct 27 '21 at 06:50
  • If you want more direct help, please also post your data or a minimal reproducible example so we know what you are working with (see here for help: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?noredirect=1&lq=1). – Mojoesque Oct 27 '21 at 08:43

0 Answers0