1

I think there is a discrepancy between the faceted plots and the individual plot.

Pay attention to mouse number 9214 in these plots:

# Make the faceted graph
fig1 = ggplot(raw, aes(raw$Bregma.)) + geom_density() + ggtitle("Fig. 1. Bregma Representation, by mouse (red = post-ex, green = post-rev)") + 
  geom_density(data = raw_excluded, aes(raw_excluded$Bregma.), color = "red") +
  geom_density(data = raw_revised, aes(raw_revised$Bregma.), color = "green")+ facet_wrap(~Mouse.ID.) 

fig1

Faceted plot

When I run the individual ggplot for that data, it looks like this, which is NOT what it looks like in the faceted image:

temp_indiv_plot = function(x) {
  temp_mouse = x
  temp_mouse_original = filter(raw, raw$Mouse.ID == temp_mouse)
  temp_mouse_revised = filter(raw_revised, raw_revised$Mouse.ID. == temp_mouse)

  ggplot(temp_mouse_original, aes(x = temp_mouse_original$Bregma.)) + geom_density() + 
    geom_density(data = temp_mouse_revised, aes(temp_mouse_revised$Bregma.), color = "green") + 
    ggtitle(temp_mouse)
}

temp_indiv_plot("8350")
temp_indiv_plot("9214")

Individual plot for mouse 9214

But I plotted another mouse (8350) to see if it was consistent, but it looks identical to the faceted graph (can't add more than 3 links until I have enough reputation, you'll have to take my word for it now).

So why is mouse 9214 different?

neilfws
  • 32,751
  • 5
  • 50
  • 63
  • 4
    It's going to be nearly impossible for anyone to help you unless they can run the code and produce the graphs themselves. As a side note, you should *never* be selecting variables using `$` inside of `aes()`. The whole purpose of having a `data` argument is that then `aes(x = variable)` looks for `variables` inside of `data`. When you do things like `aes(raw_excluded$Bregma.)` unexpected things _may_ happen. – joran Sep 06 '17 at 22:21
  • @joran 's comment applies to `dplyr` functions such as `filter`. These should read `filter(raw, Mouse.ID == ... )` – lebelinoz Sep 06 '17 at 22:31
  • 2
    It's very likely due to using dollar signs in `aes`, see [here](https://stackoverflow.com/a/32543753/2461552) – aosmith Sep 06 '17 at 22:43
  • The dollar sign worked! Thanks @joran – Westley Dang Sep 06 '17 at 23:06
  • You're right. Thanks for the resource @aosmith – Westley Dang Sep 06 '17 at 23:07

0 Answers0