简体   繁体   中英

R - using heatmaply for a 2d histogram / density

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.

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在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM