How to go from base order to column using facet_wrap?

I want to make a 2x4 array of graphs that show that distributions change over time. By default, ggplotc facet_wrapis that the top row has row 1 and 2, the second row has row 3 and 4, etc. I would like to change this so that the first column has a row in order (1-> 2-> 3-> 4), and then the second column has the next 4 series. Thus, your eye can compare immediately adjacent vertical distributions in time (as I think they should be).

+5
source share
2 answers

It looks like you need to do this with an order coefficient before calling facet_wrap:

 fac <- factor( fac, levels=as.character(c(1, 10, 2, 20, 3, 30, 4, 40) ) )

as/table facet_wrap TRUE, ( "1" ) ( "40" ) . :

 pl + facet_wrap(~fac, ncol=2, nrow=4)

, . ( - , , , , , . ?) , " ", :

> ss <- 1:8; factor(ss, levels=ss[matrix(ss, ncol=2, byrow=TRUE)])
[1] 1 2 3 4 5 6 7 8
Levels: 1 3 5 7 2 4 6 8

, , :

> ss <- 1:8; factor(ss, levels=ss[matrix(ss, nrow=2, byrow=TRUE)])
[1] 1 2 3 4 5 6 7 8
Levels: 1 5 2 6 3 7 4 8
+4

dir facet_wrap(). , :

# Horizontally
ggplot(mtcars, aes(x=hp, y=mpg)) + geom_point() + facet_wrap(~ cyl, ncol=2)

# Vertically
ggplot(mtcars, aes(x=hp, y=mpg)) + geom_point() + facet_wrap(~ cyl, ncol=2, dir="v")
+1

All Articles