3

I'm trying to do a density plot of two datasets (of different size) 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 nice plot showing that the smaller dataset has higher values but I also get a warning message saying:

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

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

Thomas
  • 43,637
  • 12
  • 109
  • 140
user3346285
  • 101
  • 1
  • 1
  • 5
  • 1
    Do you have negative numbers in your data before the log transform? That would create non-finite values which are then removed... I think the warning suggests you might not have the best understanding of your data, which may be the biggest issue here? – alexwhan Feb 24 '14 at 10:58
  • Yes, you're right, the understanding of the data is not so good, thanks a lot! – user3346285 Feb 24 '14 at 11:57
  • Actually, there are no negative numbers before the log transform, if you have any other suggestions what it might be, I would appreciate your input! – user3346285 Feb 24 '14 at 12:01
  • 6
    I get this warning when some data points get dropped because I restrict the X range of the plot using `xlim()` – Ant May 26 '15 at 01:03

1 Answers1

2

As @Ant and @alexwhan have already pointed out, the problem could be due to:

  • points that are negative or equal to zero. In the second case the log-transform would give as output -Inf, which is then dicarded in the analyisis.
  • points that are out of the range that it is possible to prescribe.

Since in your case the limit in the x- or y-axis is not set a priori, I would say that the reason is the fisrt one.

Please, see the following links for further explanations:

I hope this can help.

Community
  • 1
  • 1
Matteus
  • 86
  • 1
  • 6
  • 2
    Actually, another problem in the visualization can be triggered by the presence of 'NA' in your datasets.
    The command na.omit should then work for you.
    – Matteus Oct 05 '15 at 12:49