Simpler way to order facet_wrap plot by year
up vote
1
down vote
favorite
I have 20 years of weight data and I want to make a 10 rows by 2 columns facet_wrap figure with ggplot2. The problem is that I want to re-order the facets in such a way that I have the first ten years in the left column and the last 10 years in the right column.
I could re-order the levels manually as suggested in other posts but this is rather painful. Also, I'll have to reorder the levels again if I want to do the same thing but with different years.
Is there an easier way ? Here's an example to illustrate what I'm talking about:
sub.data$year = factor(sub.data$year,
levels = c(2000,2005,2001,2006,2002,2007,2003,2008,2004,2009...))
ggplot(data = sub.data, aes(x = sub.data$weight)) +
geom_histogram() + facet_wrap(~ year, ncol = 2)
Thank you
r ggplot2 facet-wrap
add a comment |
up vote
1
down vote
favorite
I have 20 years of weight data and I want to make a 10 rows by 2 columns facet_wrap figure with ggplot2. The problem is that I want to re-order the facets in such a way that I have the first ten years in the left column and the last 10 years in the right column.
I could re-order the levels manually as suggested in other posts but this is rather painful. Also, I'll have to reorder the levels again if I want to do the same thing but with different years.
Is there an easier way ? Here's an example to illustrate what I'm talking about:
sub.data$year = factor(sub.data$year,
levels = c(2000,2005,2001,2006,2002,2007,2003,2008,2004,2009...))
ggplot(data = sub.data, aes(x = sub.data$weight)) +
geom_histogram() + facet_wrap(~ year, ncol = 2)
Thank you
r ggplot2 facet-wrap
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have 20 years of weight data and I want to make a 10 rows by 2 columns facet_wrap figure with ggplot2. The problem is that I want to re-order the facets in such a way that I have the first ten years in the left column and the last 10 years in the right column.
I could re-order the levels manually as suggested in other posts but this is rather painful. Also, I'll have to reorder the levels again if I want to do the same thing but with different years.
Is there an easier way ? Here's an example to illustrate what I'm talking about:
sub.data$year = factor(sub.data$year,
levels = c(2000,2005,2001,2006,2002,2007,2003,2008,2004,2009...))
ggplot(data = sub.data, aes(x = sub.data$weight)) +
geom_histogram() + facet_wrap(~ year, ncol = 2)
Thank you
r ggplot2 facet-wrap
I have 20 years of weight data and I want to make a 10 rows by 2 columns facet_wrap figure with ggplot2. The problem is that I want to re-order the facets in such a way that I have the first ten years in the left column and the last 10 years in the right column.
I could re-order the levels manually as suggested in other posts but this is rather painful. Also, I'll have to reorder the levels again if I want to do the same thing but with different years.
Is there an easier way ? Here's an example to illustrate what I'm talking about:
sub.data$year = factor(sub.data$year,
levels = c(2000,2005,2001,2006,2002,2007,2003,2008,2004,2009...))
ggplot(data = sub.data, aes(x = sub.data$weight)) +
geom_histogram() + facet_wrap(~ year, ncol = 2)
Thank you
r ggplot2 facet-wrap
r ggplot2 facet-wrap
edited Nov 11 at 17:40
Julius Vainora
29.2k75878
29.2k75878
asked Nov 11 at 16:57
Blue
213
213
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
I think you need dir = "v"
.
library(tidyverse)
df <- data.frame(year = rep(2001:2020, 5), x = runif(100), y = runif(100))
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~year, ncol = 2, dir = "v")
Created on 2018-11-11 by the reprex package (v0.2.1)
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I think you need dir = "v"
.
library(tidyverse)
df <- data.frame(year = rep(2001:2020, 5), x = runif(100), y = runif(100))
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~year, ncol = 2, dir = "v")
Created on 2018-11-11 by the reprex package (v0.2.1)
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
add a comment |
up vote
2
down vote
I think you need dir = "v"
.
library(tidyverse)
df <- data.frame(year = rep(2001:2020, 5), x = runif(100), y = runif(100))
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~year, ncol = 2, dir = "v")
Created on 2018-11-11 by the reprex package (v0.2.1)
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
add a comment |
up vote
2
down vote
up vote
2
down vote
I think you need dir = "v"
.
library(tidyverse)
df <- data.frame(year = rep(2001:2020, 5), x = runif(100), y = runif(100))
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~year, ncol = 2, dir = "v")
Created on 2018-11-11 by the reprex package (v0.2.1)
I think you need dir = "v"
.
library(tidyverse)
df <- data.frame(year = rep(2001:2020, 5), x = runif(100), y = runif(100))
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(~year, ncol = 2, dir = "v")
Created on 2018-11-11 by the reprex package (v0.2.1)
answered Nov 11 at 17:16
Clemens Hug
1765
1765
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
add a comment |
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
Ah! How could I miss this ?
– Blue
Nov 12 at 18:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251046%2fsimpler-way-to-order-facet-wrap-plot-by-year%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown