2

Currently, I have two data sets with different sizes. The data sets show the how many cells appear in a specific location within an area. Cause the data sets have different sizes. With using ggplot, I achieved the normalisation by aes(fill=..density..) to get the density (percentage) of each hex. For each hex, it's the number of cells in this hex divided by the total number. My question is how do I quantify the difference between these two plots? How can I get subtraction results of these two plots?

x1 <- runif(1000,-195.5,195.5)
y1 <- runif(1000,-49,49)
data1 <- data.frame(x1,y1)
x2 <- runif(2000,-195.5,195.5)
y2 <- runif(2000,-49,49)
data2 <- data.frame(x2,y2)

outline<-"grey50"
min=-225
max=225
brks <- (max-min)/4

plot_1 <-  ggplot(data1,aes(x=x1,y=y1)) +
  geom_hex(bins=30,color=outline,alpha=1, aes(fill=..density..)) +
  scale_x_continuous(breaks= seq(min, max, brks), limits= c(min, max), labels=noDec) + 
  scale_y_continuous(breaks= seq(min, max, brks), limits= c(min, max), labels=noDec) 
plot_1

plot_2 <-  ggplot(data2,aes(x=x2,y=y2)) +
  geom_hex(bins=30,color=outline,alpha=1, aes(fill=..density..)) +
  scale_x_continuous(breaks= seq(min, max, brks), limits= c(min, max), labels=noDec) + 
  scale_y_continuous(breaks= seq(min, max, brks), limits= c(min, max), labels=noDec) 
plot_2

I also tried another method. With using hexbin function from hexbin package firstly, and then apply the hdiffplot function. The problem is how can I get the quantified result (e.g.a number or whatever) instead of a plot as results?

xbnds <- range(data1$x1,data2$x2)
ybnds <- range(data1$y1,data2$y2)
hbin_1 <- hexbin(x=data1$x1,y=data1$y1,xbins=30,xbnds=xbnds, ybnds=ybnds,shape=98/391)
hbin_2 <- hexbin(x=data2$x2,y=data2$y2,xbins=30,xbnds=xbnds,ybnds=ybnds,shape=98/391)
erodebin1 <- erode.hexbin(smooth.hexbin(hbin_1))
erodebin2 <- erode.hexbin(smooth.hexbin(hbin_2))
hdiffplot(erodebin1,erodebin2)

Thanks in advance!

Meow
  • 330
  • 1
  • 8
  • Could you share the data behind these plots using `dput(data)` – CPak Aug 13 '18 at 14:50
  • I am afraid that I can't share the data. But any suggestions would be much appreciated! – Meow Aug 13 '18 at 14:51
  • If you can't share this *exact* data, you can always make some up, find a way to anonymize, or use some commonly available data to make this a [reproducible question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – camille Aug 13 '18 at 15:34
  • I updated the question with random data. Many thanks! – Meow Aug 13 '18 at 15:59

0 Answers0