Keeping unit of measure in facet_wrap while scales=“free_y”? [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Setting individual y axis limits with facet wrap NOT with scales free_y
1 answer
I'm trying to create a facet_wrap()
where the unit of measure remains identical across the different plots, while allowing to slide across the y axis.
To clearify with I mean, I have created a dataset df
:
library(tidyverse)
df <- tibble(
Year = c(2010,2011,2012,2010,2011,2012),
Category=c("A","A","A","B","B","B"),
Value=c(1.50, 1.70, 1.60, 4.50, 4.60, 4.55)
)
with df
, we can create the following plot using facet_wrap
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() + facet_wrap(.~ Category)
Plot 1
To clarify the differences between both plots, one can use scale = "free_y"
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line()
+ facet_wrap(.~ Category, scale="free_y")
Plot 2
Although it's more clear, the scale on the y-axis in plot A
isequal to 0.025, while being 0.0125 in B
. This could be misleading to someone who's comparing A
& B
next to each other.
So my question right now is to know whether there exist an elegant way of plotting something like the graph below (with y-scale = 0.025) without having to plot two seperate plots into a grid?
Thanks
Desired result:
Code for the grid:
# Grid
## Plot A
df_A <- df %>%
filter(Category == "A")
plot_A <- ggplot(data = df_A, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(1.5,1.7)) + ggtitle("A")
## Plot B
df_B <- df %>%
filter(Category == "B")
plot_B <- ggplot(data = df_B, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(4.4,4.6)) + ggtitle("B")
grid.arrange(plot_A, plot_B, nrow=1)
r ggplot2 facet-wrap facet-grid
marked as duplicate by Community♦ Jan 5 at 13:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Setting individual y axis limits with facet wrap NOT with scales free_y
1 answer
I'm trying to create a facet_wrap()
where the unit of measure remains identical across the different plots, while allowing to slide across the y axis.
To clearify with I mean, I have created a dataset df
:
library(tidyverse)
df <- tibble(
Year = c(2010,2011,2012,2010,2011,2012),
Category=c("A","A","A","B","B","B"),
Value=c(1.50, 1.70, 1.60, 4.50, 4.60, 4.55)
)
with df
, we can create the following plot using facet_wrap
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() + facet_wrap(.~ Category)
Plot 1
To clarify the differences between both plots, one can use scale = "free_y"
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line()
+ facet_wrap(.~ Category, scale="free_y")
Plot 2
Although it's more clear, the scale on the y-axis in plot A
isequal to 0.025, while being 0.0125 in B
. This could be misleading to someone who's comparing A
& B
next to each other.
So my question right now is to know whether there exist an elegant way of plotting something like the graph below (with y-scale = 0.025) without having to plot two seperate plots into a grid?
Thanks
Desired result:
Code for the grid:
# Grid
## Plot A
df_A <- df %>%
filter(Category == "A")
plot_A <- ggplot(data = df_A, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(1.5,1.7)) + ggtitle("A")
## Plot B
df_B <- df %>%
filter(Category == "B")
plot_B <- ggplot(data = df_B, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(4.4,4.6)) + ggtitle("B")
grid.arrange(plot_A, plot_B, nrow=1)
r ggplot2 facet-wrap facet-grid
marked as duplicate by Community♦ Jan 5 at 13:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
+ scale_y_continuous(breaks = seq(0, 5, by = 0.025))
– Jack Brookes
Jan 4 at 13:37
Thanks for your response, Jack! This could help the clearify the differences in scale between the two plot. I'm still curious to discover whether it's possible to come up with a result as in plot 3.
– Reindert Van Herreweghe
Jan 4 at 13:44
1
stackoverflow.com/questions/51735481/… - does this post help at all?
– Mike
Jan 4 at 15:00
add a comment |
This question already has an answer here:
Setting individual y axis limits with facet wrap NOT with scales free_y
1 answer
I'm trying to create a facet_wrap()
where the unit of measure remains identical across the different plots, while allowing to slide across the y axis.
To clearify with I mean, I have created a dataset df
:
library(tidyverse)
df <- tibble(
Year = c(2010,2011,2012,2010,2011,2012),
Category=c("A","A","A","B","B","B"),
Value=c(1.50, 1.70, 1.60, 4.50, 4.60, 4.55)
)
with df
, we can create the following plot using facet_wrap
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() + facet_wrap(.~ Category)
Plot 1
To clarify the differences between both plots, one can use scale = "free_y"
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line()
+ facet_wrap(.~ Category, scale="free_y")
Plot 2
Although it's more clear, the scale on the y-axis in plot A
isequal to 0.025, while being 0.0125 in B
. This could be misleading to someone who's comparing A
& B
next to each other.
So my question right now is to know whether there exist an elegant way of plotting something like the graph below (with y-scale = 0.025) without having to plot two seperate plots into a grid?
Thanks
Desired result:
Code for the grid:
# Grid
## Plot A
df_A <- df %>%
filter(Category == "A")
plot_A <- ggplot(data = df_A, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(1.5,1.7)) + ggtitle("A")
## Plot B
df_B <- df %>%
filter(Category == "B")
plot_B <- ggplot(data = df_B, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(4.4,4.6)) + ggtitle("B")
grid.arrange(plot_A, plot_B, nrow=1)
r ggplot2 facet-wrap facet-grid
This question already has an answer here:
Setting individual y axis limits with facet wrap NOT with scales free_y
1 answer
I'm trying to create a facet_wrap()
where the unit of measure remains identical across the different plots, while allowing to slide across the y axis.
To clearify with I mean, I have created a dataset df
:
library(tidyverse)
df <- tibble(
Year = c(2010,2011,2012,2010,2011,2012),
Category=c("A","A","A","B","B","B"),
Value=c(1.50, 1.70, 1.60, 4.50, 4.60, 4.55)
)
with df
, we can create the following plot using facet_wrap
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() + facet_wrap(.~ Category)
Plot 1
To clarify the differences between both plots, one can use scale = "free_y"
:
ggplot(data = df, aes(x=Year, y=Value)) + geom_line()
+ facet_wrap(.~ Category, scale="free_y")
Plot 2
Although it's more clear, the scale on the y-axis in plot A
isequal to 0.025, while being 0.0125 in B
. This could be misleading to someone who's comparing A
& B
next to each other.
So my question right now is to know whether there exist an elegant way of plotting something like the graph below (with y-scale = 0.025) without having to plot two seperate plots into a grid?
Thanks
Desired result:
Code for the grid:
# Grid
## Plot A
df_A <- df %>%
filter(Category == "A")
plot_A <- ggplot(data = df_A, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(1.5,1.7)) + ggtitle("A")
## Plot B
df_B <- df %>%
filter(Category == "B")
plot_B <- ggplot(data = df_B, aes(x=Year, y=Value)) + geom_line() + coord_cartesian(ylim = c(4.4,4.6)) + ggtitle("B")
grid.arrange(plot_A, plot_B, nrow=1)
This question already has an answer here:
Setting individual y axis limits with facet wrap NOT with scales free_y
1 answer
r ggplot2 facet-wrap facet-grid
r ggplot2 facet-wrap facet-grid
asked Jan 4 at 13:31
Reindert Van HerrewegheReindert Van Herreweghe
255
255
marked as duplicate by Community♦ Jan 5 at 13:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Community♦ Jan 5 at 13:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
+ scale_y_continuous(breaks = seq(0, 5, by = 0.025))
– Jack Brookes
Jan 4 at 13:37
Thanks for your response, Jack! This could help the clearify the differences in scale between the two plot. I'm still curious to discover whether it's possible to come up with a result as in plot 3.
– Reindert Van Herreweghe
Jan 4 at 13:44
1
stackoverflow.com/questions/51735481/… - does this post help at all?
– Mike
Jan 4 at 15:00
add a comment |
1
+ scale_y_continuous(breaks = seq(0, 5, by = 0.025))
– Jack Brookes
Jan 4 at 13:37
Thanks for your response, Jack! This could help the clearify the differences in scale between the two plot. I'm still curious to discover whether it's possible to come up with a result as in plot 3.
– Reindert Van Herreweghe
Jan 4 at 13:44
1
stackoverflow.com/questions/51735481/… - does this post help at all?
– Mike
Jan 4 at 15:00
1
1
+ scale_y_continuous(breaks = seq(0, 5, by = 0.025))
– Jack Brookes
Jan 4 at 13:37
+ scale_y_continuous(breaks = seq(0, 5, by = 0.025))
– Jack Brookes
Jan 4 at 13:37
Thanks for your response, Jack! This could help the clearify the differences in scale between the two plot. I'm still curious to discover whether it's possible to come up with a result as in plot 3.
– Reindert Van Herreweghe
Jan 4 at 13:44
Thanks for your response, Jack! This could help the clearify the differences in scale between the two plot. I'm still curious to discover whether it's possible to come up with a result as in plot 3.
– Reindert Van Herreweghe
Jan 4 at 13:44
1
1
stackoverflow.com/questions/51735481/… - does this post help at all?
– Mike
Jan 4 at 15:00
stackoverflow.com/questions/51735481/… - does this post help at all?
– Mike
Jan 4 at 15:00
add a comment |
1 Answer
1
active
oldest
votes
Based on the info at Setting individual y axis limits with facet wrap NOT with scales free_y you can you use geom_blank()
and manually specified y-limits by Category
:
# df from above code
df2 <- tibble(
Category = c("A", "B"),
y_min = c(1.5, 4.4),
y_max = c(1.7, 4.6)
)
df <- full_join(df, df2, by = "Category")
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() +
facet_wrap(.~ Category, scales = "free_y") +
geom_blank(aes(y = y_min)) +
geom_blank(aes(y = y_max))
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Based on the info at Setting individual y axis limits with facet wrap NOT with scales free_y you can you use geom_blank()
and manually specified y-limits by Category
:
# df from above code
df2 <- tibble(
Category = c("A", "B"),
y_min = c(1.5, 4.4),
y_max = c(1.7, 4.6)
)
df <- full_join(df, df2, by = "Category")
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() +
facet_wrap(.~ Category, scales = "free_y") +
geom_blank(aes(y = y_min)) +
geom_blank(aes(y = y_max))
add a comment |
Based on the info at Setting individual y axis limits with facet wrap NOT with scales free_y you can you use geom_blank()
and manually specified y-limits by Category
:
# df from above code
df2 <- tibble(
Category = c("A", "B"),
y_min = c(1.5, 4.4),
y_max = c(1.7, 4.6)
)
df <- full_join(df, df2, by = "Category")
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() +
facet_wrap(.~ Category, scales = "free_y") +
geom_blank(aes(y = y_min)) +
geom_blank(aes(y = y_max))
add a comment |
Based on the info at Setting individual y axis limits with facet wrap NOT with scales free_y you can you use geom_blank()
and manually specified y-limits by Category
:
# df from above code
df2 <- tibble(
Category = c("A", "B"),
y_min = c(1.5, 4.4),
y_max = c(1.7, 4.6)
)
df <- full_join(df, df2, by = "Category")
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() +
facet_wrap(.~ Category, scales = "free_y") +
geom_blank(aes(y = y_min)) +
geom_blank(aes(y = y_max))
Based on the info at Setting individual y axis limits with facet wrap NOT with scales free_y you can you use geom_blank()
and manually specified y-limits by Category
:
# df from above code
df2 <- tibble(
Category = c("A", "B"),
y_min = c(1.5, 4.4),
y_max = c(1.7, 4.6)
)
df <- full_join(df, df2, by = "Category")
ggplot(data = df, aes(x=Year, y=Value)) + geom_line() +
facet_wrap(.~ Category, scales = "free_y") +
geom_blank(aes(y = y_min)) +
geom_blank(aes(y = y_max))
answered Jan 5 at 3:23
r_alanbr_alanb
408317
408317
add a comment |
add a comment |
1
+ scale_y_continuous(breaks = seq(0, 5, by = 0.025))
– Jack Brookes
Jan 4 at 13:37
Thanks for your response, Jack! This could help the clearify the differences in scale between the two plot. I'm still curious to discover whether it's possible to come up with a result as in plot 3.
– Reindert Van Herreweghe
Jan 4 at 13:44
1
stackoverflow.com/questions/51735481/… - does this post help at all?
– Mike
Jan 4 at 15:00