CodeGuy
CodeGuy

Reputation: 28907

R - Heatmap from sparse 2d data

I'd like to achieve what this person has achieved without using ggplot. Any ideas?

How do I create a continuous density heatmap of 2D scatter data in R?

You can see what I get when using the solution detailed in that question.

ggplot(df,aes(x=x,y=y))+
  stat_density2d(aes(alpha=..level..), geom="polygon") +
  scale_alpha_continuous(limits=c(0,1),breaks=seq(0,1,by=0.1))+
  geom_point(colour="red",alpha=0.2)+
  theme_bw()

The heatmap is so sparse. I want it to cover much more than what it is covering now. It's terribly hard to see anything about the density. Any ideas of different ways to make density heatmaps from 2D data besides this ggplot solution? enter image description here

One idea I had was instead of using linear color labeling (see the black to white spectrum on the left, which is linear), using logarithmic scale for the density labeling. Any ideas how I could do this?

Upvotes: 1

Views: 1502

Answers (2)

CodeGuy
CodeGuy

Reputation: 28907

I actually ended up using smoothScatter, which works well and uses classic R plotting.

Upvotes: 2

smci
smci

Reputation: 33940

"The heatmap is so sparse. I want it to cover much more than what it is covering now. It's terribly hard to see anything about the density."

Please be specific: what do you want to see in areas with most or all NAs?

Upvotes: 2

Related Questions