0

I am trying to compile 35 graphs together, and sort them based on the columns "size" and "behavior". Individually, the graphs are composed of movement data over time. I would like my size categories to sort vertically and the behavior to sort horizontally.

I can compile the 35 graphs together with the following code:

g<-ggplot(data,aes(x=time,y=distance))+
  geom_point(aes(color=Location))+
  scale_x_datetime(name="Date", date_breaks="1 months",labels=date_format(format="%b-%Y")) +
  theme(axis.text.x=element_text(angle = 90,size=5, hjust = 0))+
  ggtitle("All Plots")+
  theme(plot.title = element_text(hjust = 0.5)) +
  ylab("distance") + 
  facet_wrap( ~ individual,labeller = label_parsed)

I would like these graphs to be sorted vertically by size class, and horizontally as behavior.

I have tried to include size and behavior in facet_wrap like so:

g + facet_wrap(size ~ individual + behavior, label = label_wrap_gen(multi_line=FALSE))

But this only pastes the size and behavior under individual on each graph.

I have also tried facet_grid:

g + facet_grid(data$size, data$behavior)

And get the following error: rows must be NULL or a vars() list if cols is a vars() list.

Am I going about this in the wrong way? Any help is much appreciated!

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Maybe share a smaller set for demonstration purposes rather than the data for all 35 graphs. – MrFlick Mar 05 '19 at 20:28
  • 2
    To do two-way facets, you need `facet_grid`, not `facet_wrap` – camille Mar 05 '19 at 20:56
  • 1
    You are facetting by `individual`. You can't really give ordering arguments in `facet_wrap` or `facet_grid`. You can order the `individual` factor before-hand though. Unless you have a nicely balanced factorial design, with one individual for each combination. Then you just do `facet_grid(size ~ behavior)`. Hard to help more without a reproducible example. – Axeman Mar 05 '19 at 20:57

0 Answers0