0

First question to the group- I hope it has an easy answer: I have noticed odd behavior in ggplot with facets. My dataset contians longitude, latitude and a zipcode for schools over 16 years. I have noticed that the sort order of the data sets produces different plots, and I can't find documentation supporting this.

For example, this produces a map I don't believe:

SchoolDiscipline <- SchoolDiscipline[with(SchoolDiscipline, order(zip, YEAR)), ]

mo_base +
  geom_point(aes(x = SchoolDiscipline$long, y = SchoolDiscipline$lat),
             data = SchoolDiscipline, 
             alpha = .50, inherit.aes = FALSE) + 
  facet_wrap(~YEAR, ncol = 4)

Map I don't believe

while this produces a map I do believe:

SchoolDiscipline <- SchoolDiscipline[with(SchoolDiscipline, order(YEAR, zip)), ]

mo_base+
  geom_point(aes(x = SchoolDiscipline$long, y = SchoolDiscipline$lat),
             data = SchoolDiscipline, 
             alpha = .50, inherit.aes = FALSE) + 
  facet_wrap(~YEAR, ncol=4)

Map I do believe

Can anyone explain this behavior? many thanks!

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • If you could add some data and make the whole example reproducible I am confident the potential problem with the code, or a bug if it exists, will be found. – missuse Oct 05 '17 at 20:31
  • The problem is reproducible only if I keep the first 700 observations in a data set composed of longitude, latitude, zipcode and year. I'd assume that's too large to post here, but, given that this my first post to the group, I'd be happy to post it if that's within the standards for the group. Smaller samples do not generate the problem- I get the same plots under both sort orders. – Phil Wood Oct 06 '17 at 02:10
  • Without having access to your data, the only advice I can offer is to remove the `SchoolDiscipline$` portion from your `aes()` mappings in each ggplot call. That may be messing up the link between your variables. See [here](https://stackoverflow.com/questions/32543340/behavior-ggplot2-aes-in-combination-with-facet-grid-when-passing-variable-wi) for a more thorough discussion. – Z.Lin Oct 12 '17 at 05:42

0 Answers0