R - using heatmaply for a 2d histogram / density

82 views Asked by At

I'm rather new to programming and the site so let me know if I screw up on this explanation.

I have a rather long series of x, y coordinates representing a character in 2d space. Let's say that space is 200 x 400. I want to represent the amount of time the character is in each x, y coordinate by means of a pretty chloropleth.

I want to use heatmaply for this because I think the output is pretty and I want my audience to be able to zoom in on the data. It isn't really meant to do density estimation (I think?) so I'm trying to work around it.

I suppose the way to do this is to fill a 200x400 dataframe with counts of the number of occurrences of each x, y coordinate in the data at each x, y coordinate in the frame. Essentially, to build a 2d map out of the data frame and impose the counts upon it

So, I suppose my questions are:

1). How do I get the count of each unique x, y coordinate in my set

2). How might I pass those counts easily to the matching x, y cell in my 200x400 dataframe full of zeroes?

This seems like it should be easy but I can't seem to figure it out! I'm a novice to r and can't see the shape of what I need to do.

1

There are 1 answers

2
Hasan Bhagat On BEST ANSWER

You can use the table function to get your matrix of counts.

table(X,Y)

X and Y should be columns of coordinates.

Output based on some sample data enter image description here