geom_histogram and geom_blank: controlling y limits
up vote
0
down vote
favorite
I want to create a set of histograms that will make use of facet_wrap. The y limits vary a lot, sometimes there is no data for a given combination. So, I thought I could control the y limits using a dummy data frame and geom_blank.
Geom_blank() works as expected when I use geom_point() but not when when I use geom_histogram()
For example, I create these two data frames
test <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=rep(1:3, each=2))
dummy <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=c(0,10,10,20,20,30))
If I want to do a scatterplot:
p1 <- ggplot(test, aes(x=x.value, y=y.value)) + geom_point()
p1 <- p1 + facet_wrap(~grp, scales="free")
p1
p2 <- p1 + geom_blank(data=dummy)
p2
geom_blank() changed the y limits.
But when I try to create a histogram
p3 <- ggplot(test, aes(x=x.value, weight=y.value)) + geom_histogram(bins=6)
p3 <- p3 + facet_wrap(~grp, scales="free")
p3
p4 <- p3 + geom_blank(data=dummy)
p4
geom_blank() has no impact.
How can I control complex y limits on a set of histograms?
r ggplot2
add a comment |
up vote
0
down vote
favorite
I want to create a set of histograms that will make use of facet_wrap. The y limits vary a lot, sometimes there is no data for a given combination. So, I thought I could control the y limits using a dummy data frame and geom_blank.
Geom_blank() works as expected when I use geom_point() but not when when I use geom_histogram()
For example, I create these two data frames
test <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=rep(1:3, each=2))
dummy <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=c(0,10,10,20,20,30))
If I want to do a scatterplot:
p1 <- ggplot(test, aes(x=x.value, y=y.value)) + geom_point()
p1 <- p1 + facet_wrap(~grp, scales="free")
p1
p2 <- p1 + geom_blank(data=dummy)
p2
geom_blank() changed the y limits.
But when I try to create a histogram
p3 <- ggplot(test, aes(x=x.value, weight=y.value)) + geom_histogram(bins=6)
p3 <- p3 + facet_wrap(~grp, scales="free")
p3
p4 <- p3 + geom_blank(data=dummy)
p4
geom_blank() has no impact.
How can I control complex y limits on a set of histograms?
r ggplot2
Did my answer help you solve your issue?
– markus
Nov 22 at 21:44
Yes. It works. Awesome. Thanks.
– user13424
Nov 23 at 13:44
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to create a set of histograms that will make use of facet_wrap. The y limits vary a lot, sometimes there is no data for a given combination. So, I thought I could control the y limits using a dummy data frame and geom_blank.
Geom_blank() works as expected when I use geom_point() but not when when I use geom_histogram()
For example, I create these two data frames
test <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=rep(1:3, each=2))
dummy <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=c(0,10,10,20,20,30))
If I want to do a scatterplot:
p1 <- ggplot(test, aes(x=x.value, y=y.value)) + geom_point()
p1 <- p1 + facet_wrap(~grp, scales="free")
p1
p2 <- p1 + geom_blank(data=dummy)
p2
geom_blank() changed the y limits.
But when I try to create a histogram
p3 <- ggplot(test, aes(x=x.value, weight=y.value)) + geom_histogram(bins=6)
p3 <- p3 + facet_wrap(~grp, scales="free")
p3
p4 <- p3 + geom_blank(data=dummy)
p4
geom_blank() has no impact.
How can I control complex y limits on a set of histograms?
r ggplot2
I want to create a set of histograms that will make use of facet_wrap. The y limits vary a lot, sometimes there is no data for a given combination. So, I thought I could control the y limits using a dummy data frame and geom_blank.
Geom_blank() works as expected when I use geom_point() but not when when I use geom_histogram()
For example, I create these two data frames
test <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=rep(1:3, each=2))
dummy <- data.frame(grp=rep(c("a", "b"),3), x.value=rep(c(10,20,30), each=2),
y.value=c(0,10,10,20,20,30))
If I want to do a scatterplot:
p1 <- ggplot(test, aes(x=x.value, y=y.value)) + geom_point()
p1 <- p1 + facet_wrap(~grp, scales="free")
p1
p2 <- p1 + geom_blank(data=dummy)
p2
geom_blank() changed the y limits.
But when I try to create a histogram
p3 <- ggplot(test, aes(x=x.value, weight=y.value)) + geom_histogram(bins=6)
p3 <- p3 + facet_wrap(~grp, scales="free")
p3
p4 <- p3 + geom_blank(data=dummy)
p4
geom_blank() has no impact.
How can I control complex y limits on a set of histograms?
r ggplot2
r ggplot2
edited Nov 21 at 21:16
markus
8,565928
8,565928
asked Nov 21 at 20:58
user13424
324
324
Did my answer help you solve your issue?
– markus
Nov 22 at 21:44
Yes. It works. Awesome. Thanks.
– user13424
Nov 23 at 13:44
add a comment |
Did my answer help you solve your issue?
– markus
Nov 22 at 21:44
Yes. It works. Awesome. Thanks.
– user13424
Nov 23 at 13:44
Did my answer help you solve your issue?
– markus
Nov 22 at 21:44
Did my answer help you solve your issue?
– markus
Nov 22 at 21:44
Yes. It works. Awesome. Thanks.
– user13424
Nov 23 at 13:44
Yes. It works. Awesome. Thanks.
– user13424
Nov 23 at 13:44
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You need to map y.value
to y
like you did in p1
and p2
.
p4 <- p3 + geom_blank(aes(y = y.value), data=dummy)
p4
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to map y.value
to y
like you did in p1
and p2
.
p4 <- p3 + geom_blank(aes(y = y.value), data=dummy)
p4
add a comment |
up vote
1
down vote
accepted
You need to map y.value
to y
like you did in p1
and p2
.
p4 <- p3 + geom_blank(aes(y = y.value), data=dummy)
p4
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to map y.value
to y
like you did in p1
and p2
.
p4 <- p3 + geom_blank(aes(y = y.value), data=dummy)
p4
You need to map y.value
to y
like you did in p1
and p2
.
p4 <- p3 + geom_blank(aes(y = y.value), data=dummy)
p4
edited Nov 21 at 21:21
answered Nov 21 at 21:15
markus
8,565928
8,565928
add a comment |
add a comment |
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%2f53420379%2fgeom-histogram-and-geom-blank-controlling-y-limits%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
Did my answer help you solve your issue?
– markus
Nov 22 at 21:44
Yes. It works. Awesome. Thanks.
– user13424
Nov 23 at 13:44