Warning message in overlay density graph in ggplot2

I am trying to plot the density of two data sets (of different sizes) by writing:

data1 <- data.frame(dens = log2(c(tmm.th[,1],bidrar_mest[,1]))
                  , lines = c(rep("all",61893),rep("loaded",50) ))

ggplot(data1, aes(x = dens, fill = lines)) + geom_density(alpha = 0.5)

I get a good graph showing that a smaller dataset has higher values, but I also get a warning message:

Warning message: Removed 35492 rows containing non-finite values
(stat_density).

Can someone explain why and how to get rid of this?

+3
source share
1 answer

As @ Ant and @alexwhan already noted, the problem may be caused by:

  • negative or equal to zero. In the second case, the logarithm transformation will give -Inf as the output, which is then analyzed in the analysis.
  • which are outside the range that you can prescribe.

x y , , - .

. :

, .

+2

All Articles