extend ggplot `geom_ribbon()` in the x directionggplot: How to change facet labels?Turning off some legends in a ggplotHow to change legend title in ggplotremove legend title in ggplotMatplotlib equivalent to ggplot geom_ribbon?Controlling rectangular geom_ribbon in R ggplotRemove all of x axis labels in ggplotRemove legend ggplot 2.2Extended range in geom_ribbonR ggplot: geom_ribbon is making export extremely slow
What would happen to a modern skyscraper if it rains micro blackholes?
How can I make my BBEG immortal short of making them a Lich or Vampire?
How to write a macro that is braces sensitive?
How does strength of boric acid solution increase in presence of salicylic acid?
Why was the small council so happy for Tyrion to become the Master of Coin?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Why can't I see bouncing of a switch on an oscilloscope?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Replacing matching entries in one column of a file by another column from a different file
What defenses are there against being summoned by the Gate spell?
Watching something be written to a file live with tail
Pattern match does not work in bash script
What are these boxed doors outside store fronts in New York?
Why do I get two different answers for this counting problem?
Adding span tags within wp_list_pages list items
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Mathematical cryptic clues
Risk of getting Chronic Wasting Disease (CWD) in the United States?
What are the differences between the usage of 'it' and 'they'?
Why not use SQL instead of GraphQL?
tikz: show 0 at the axis origin
Why does Kotter return in Welcome Back Kotter?
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
Today is the Center
extend ggplot `geom_ribbon()` in the x direction
ggplot: How to change facet labels?Turning off some legends in a ggplotHow to change legend title in ggplotremove legend title in ggplotMatplotlib equivalent to ggplot geom_ribbon?Controlling rectangular geom_ribbon in R ggplotRemove all of x axis labels in ggplotRemove legend ggplot 2.2Extended range in geom_ribbonR ggplot: geom_ribbon is making export extremely slow
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
library(tidyverse)
mQ <- quantile(mtcars$wt, c(0.025, 0.975))
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)),
max(as.numeric(diamonds$cut))),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
I'd like to extend my geom_ribbon()
from code chunk above in either direction on the x-axis. Something resembling the image below. My preferred geom_ribbon()
would fully entend into the blue dotted line box.
How do I do this?
r ggplot2
add a comment |
library(tidyverse)
mQ <- quantile(mtcars$wt, c(0.025, 0.975))
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)),
max(as.numeric(diamonds$cut))),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
I'd like to extend my geom_ribbon()
from code chunk above in either direction on the x-axis. Something resembling the image below. My preferred geom_ribbon()
would fully entend into the blue dotted line box.
How do I do this?
r ggplot2
add a comment |
library(tidyverse)
mQ <- quantile(mtcars$wt, c(0.025, 0.975))
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)),
max(as.numeric(diamonds$cut))),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
I'd like to extend my geom_ribbon()
from code chunk above in either direction on the x-axis. Something resembling the image below. My preferred geom_ribbon()
would fully entend into the blue dotted line box.
How do I do this?
r ggplot2
library(tidyverse)
mQ <- quantile(mtcars$wt, c(0.025, 0.975))
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)),
max(as.numeric(diamonds$cut))),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
I'd like to extend my geom_ribbon()
from code chunk above in either direction on the x-axis. Something resembling the image below. My preferred geom_ribbon()
would fully entend into the blue dotted line box.
How do I do this?
r ggplot2
r ggplot2
asked Mar 21 at 23:41
Jason HunterJason Hunter
39419
39419
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could subtract/add 0.5 from mtcarsQ$x
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)) - 0.5,
max(as.numeric(diamonds$cut)) + 0.5),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
Update
In response to your comment, here is an example
mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
geom_col(aes(cyl, mpg)) +
geom_rect(
data = data.frame(
xmin = min(as.integer(as.factor(mtcars$cyl))) - 0.5,
xmax = max(as.integer(as.factor(mtcars$cyl))) + 0.5,
ymin = 20,
ymax = 120),
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
alpha = 0.2, fill = "green")
And I just thought of this, what do you do whenx
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.
– Jason Hunter
Mar 21 at 23:56
1
@JasonHunter Not sure what you mean. The same principle still applies forfactor
s.
– Maurits Evers
Mar 21 at 23:58
If I put ageom_ribbon()
on the following plot, your extension technique wouldn't work becausex
is a factor? Am I thinking about this wrong:ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks
– Jason Hunter
Mar 22 at 0:09
1
Convert from factor to numeric?as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
1
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55290819%2fextend-ggplot-geom-ribbon-in-the-x-direction%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could subtract/add 0.5 from mtcarsQ$x
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)) - 0.5,
max(as.numeric(diamonds$cut)) + 0.5),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
Update
In response to your comment, here is an example
mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
geom_col(aes(cyl, mpg)) +
geom_rect(
data = data.frame(
xmin = min(as.integer(as.factor(mtcars$cyl))) - 0.5,
xmax = max(as.integer(as.factor(mtcars$cyl))) + 0.5,
ymin = 20,
ymax = 120),
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
alpha = 0.2, fill = "green")
And I just thought of this, what do you do whenx
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.
– Jason Hunter
Mar 21 at 23:56
1
@JasonHunter Not sure what you mean. The same principle still applies forfactor
s.
– Maurits Evers
Mar 21 at 23:58
If I put ageom_ribbon()
on the following plot, your extension technique wouldn't work becausex
is a factor? Am I thinking about this wrong:ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks
– Jason Hunter
Mar 22 at 0:09
1
Convert from factor to numeric?as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
1
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
add a comment |
You could subtract/add 0.5 from mtcarsQ$x
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)) - 0.5,
max(as.numeric(diamonds$cut)) + 0.5),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
Update
In response to your comment, here is an example
mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
geom_col(aes(cyl, mpg)) +
geom_rect(
data = data.frame(
xmin = min(as.integer(as.factor(mtcars$cyl))) - 0.5,
xmax = max(as.integer(as.factor(mtcars$cyl))) + 0.5,
ymin = 20,
ymax = 120),
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
alpha = 0.2, fill = "green")
And I just thought of this, what do you do whenx
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.
– Jason Hunter
Mar 21 at 23:56
1
@JasonHunter Not sure what you mean. The same principle still applies forfactor
s.
– Maurits Evers
Mar 21 at 23:58
If I put ageom_ribbon()
on the following plot, your extension technique wouldn't work becausex
is a factor? Am I thinking about this wrong:ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks
– Jason Hunter
Mar 22 at 0:09
1
Convert from factor to numeric?as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
1
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
add a comment |
You could subtract/add 0.5 from mtcarsQ$x
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)) - 0.5,
max(as.numeric(diamonds$cut)) + 0.5),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
Update
In response to your comment, here is an example
mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
geom_col(aes(cyl, mpg)) +
geom_rect(
data = data.frame(
xmin = min(as.integer(as.factor(mtcars$cyl))) - 0.5,
xmax = max(as.integer(as.factor(mtcars$cyl))) + 0.5,
ymin = 20,
ymax = 120),
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
alpha = 0.2, fill = "green")
You could subtract/add 0.5 from mtcarsQ$x
mtcarsQ <- data.frame(x = c(min(as.numeric(diamonds$cut)) - 0.5,
max(as.numeric(diamonds$cut)) + 0.5),
ymin = rep(mQ[1], 2),
ymax = rep(mQ[2], 2))
ggplot() +
geom_blank(data = diamonds, aes(x = cut, y = y)) +
geom_ribbon(data = mtcarsQ, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) +
geom_boxplot(data = diamonds, aes(x = cut, y = y, fill = cut, group = cut)) +
coord_cartesian(ylim = c(0, 12)) +
theme_bw()
Update
In response to your comment, here is an example
mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot() +
geom_col(aes(cyl, mpg)) +
geom_rect(
data = data.frame(
xmin = min(as.integer(as.factor(mtcars$cyl))) - 0.5,
xmax = max(as.integer(as.factor(mtcars$cyl))) + 0.5,
ymin = 20,
ymax = 120),
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
alpha = 0.2, fill = "green")
edited Mar 22 at 3:06
answered Mar 21 at 23:47
Maurits EversMaurits Evers
30.4k41637
30.4k41637
And I just thought of this, what do you do whenx
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.
– Jason Hunter
Mar 21 at 23:56
1
@JasonHunter Not sure what you mean. The same principle still applies forfactor
s.
– Maurits Evers
Mar 21 at 23:58
If I put ageom_ribbon()
on the following plot, your extension technique wouldn't work becausex
is a factor? Am I thinking about this wrong:ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks
– Jason Hunter
Mar 22 at 0:09
1
Convert from factor to numeric?as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
1
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
add a comment |
And I just thought of this, what do you do whenx
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.
– Jason Hunter
Mar 21 at 23:56
1
@JasonHunter Not sure what you mean. The same principle still applies forfactor
s.
– Maurits Evers
Mar 21 at 23:58
If I put ageom_ribbon()
on the following plot, your extension technique wouldn't work becausex
is a factor? Am I thinking about this wrong:ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks
– Jason Hunter
Mar 22 at 0:09
1
Convert from factor to numeric?as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
1
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
And I just thought of this, what do you do when
x
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.– Jason Hunter
Mar 21 at 23:56
And I just thought of this, what do you do when
x
is a factor? Maybe I need to put another new question. Thanks for the answer. Will accept an answer after the standard 24 hour wait time.– Jason Hunter
Mar 21 at 23:56
1
1
@JasonHunter Not sure what you mean. The same principle still applies for
factor
s.– Maurits Evers
Mar 21 at 23:58
@JasonHunter Not sure what you mean. The same principle still applies for
factor
s.– Maurits Evers
Mar 21 at 23:58
If I put a
geom_ribbon()
on the following plot, your extension technique wouldn't work because x
is a factor? Am I thinking about this wrong: ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks– Jason Hunter
Mar 22 at 0:09
If I put a
geom_ribbon()
on the following plot, your extension technique wouldn't work because x
is a factor? Am I thinking about this wrong: ggplot(mtcars %>% mutate(cyl = factor(cyl)), aes(cyl, mpg)) + geom_col()
. I've got to run but will ponder this more in a bit. Thanks– Jason Hunter
Mar 22 at 0:09
1
1
Convert from factor to numeric?
as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
Convert from factor to numeric?
as.integer(factor(cyl)))
– Jack Brookes
Mar 22 at 0:14
1
1
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
@JasonHunter I've updated my post to include an example in response to your last comment.
– Maurits Evers
Mar 22 at 5:13
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.
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%2f55290819%2fextend-ggplot-geom-ribbon-in-the-x-direction%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