everyone! I am new to R and would like to create a heatmap. There is a data set with columns:
- X: x coordinate
- Y: y coordinate
- Pet_type: type of pet (cat, dog, hamster, etc)
- Owner_type: type of owner (adult male, adult female, kid)
Small dataset:
Owner | Pet | X | Y |
---|---|---|---|
Male | Dog | 27.793 | 88.2128 |
Male | Hamster | 37.7177 | 87.9776 |
Female | Cat | 24.4547 | 87.3016 |
Kid | Cat | 36.464 | 84.9169 |
Kid | Dog | 29.4175 | 84.5433 |
Female | Lizard | 37.9588 | 83.9029 |
Male | Guinea pig | 44.8986 | 82.7822 |
Kid | Dog | 26.6216 | 82.0757 |
Male | Hamster | 46.2332 | 81.9817 |
Male | Cat | 31.9716 | 81.7507 |
Female | Cat | 22.8606 | 80.9761 |
Kid | Dog | 29.744 | 80.7988 |
Kid | Lizard | 32.2393 | 80.35 |
Female | Guinea pig | 38.92 | 78.8604 |
Male | Dog | 39.42 | 78.3604 |
Kid | Hamster | 32.2632 | 87.8267 |
What would be the steps to create a heatmap which shows the ratio of one specific pet vs all pets in that specific bin? For example: I want to create a heatmap of Cats density and if the bin consists of 20 pets and 10 of those are cats - the bin's value is 0,5 or 50%, etc.
I am using ggplot and I got that far that I can see count of total pets in each bin. What manipulations should I do to the table, before feeding it to ggplot?
df %>%
ggplot(aes(X, Y))+
geom_bin_2d(bins=15)
I am struggling to understand how to create a statement that I want to see Cats vs all pets ratio in all bins.
So yeah, I would really appreciate if someone could help me with this problem (probably an easy one)