Multiple qqplots on one gragh and single abline ggplot2 R
Borrowing from the example QQ plot: More than two data, how can one possibly implement it in ggplot2
? I need one abline
only.
Sample data:
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
sim1...sim6
should have different colors.
All suggestions are welcome.
r ggplot2
add a comment |
Borrowing from the example QQ plot: More than two data, how can one possibly implement it in ggplot2
? I need one abline
only.
Sample data:
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
sim1...sim6
should have different colors.
All suggestions are welcome.
r ggplot2
add a comment |
Borrowing from the example QQ plot: More than two data, how can one possibly implement it in ggplot2
? I need one abline
only.
Sample data:
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
sim1...sim6
should have different colors.
All suggestions are welcome.
r ggplot2
Borrowing from the example QQ plot: More than two data, how can one possibly implement it in ggplot2
? I need one abline
only.
Sample data:
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
sim1...sim6
should have different colors.
All suggestions are welcome.
r ggplot2
r ggplot2
asked Nov 23 '18 at 20:26
code123code123
7481629
7481629
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Straightforward in ggplot2
with stat_qq
and reshaping your data from wide to long.
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot <- dat %>%
gather(variable, value, -Observed) %>%
ggplot(aes(sample = value, color = variable)) +
geom_abline() +
stat_qq()
# All in one
plot
It might be beneficial if you look at making facets or small multiples along your comparison variable.
# Facets!
plot +
facet_wrap(~variable)
If you're looking to provide your own observed, then rather than being fancy, let qqplot
do the heavy lifting but set plot.it = FALSE
and it will return you a list of x/y coords for the qq plot. A little iteration with purrr::map_dfr
, and you can do:
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1 = rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot_data <- map_dfr(names(dat)[-1], ~as_tibble(qqplot(dat[[.x]], dat$Observed, plot.it = FALSE)) %>%
mutate(id = .x))
ggplot(plot_data, aes(x, y, color = id)) +
geom_point() +
geom_abline() +
facet_wrap(~id)
Created on 2018-11-25 by the reprex package (v0.2.1)
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
stat_qq
andgeom_qq
seem to seem to be designed to compare one or more vectorse.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors,e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but inggplot2
? Thank you.
– code123
Nov 25 '18 at 18:44
This is where you would conduct your comparison outside of ggplot, then just usegeom_point
to plot your expected vs observed.
– Jake Kaupp
Nov 25 '18 at 21:33
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
1
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
|
show 1 more 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%2f53452588%2fmultiple-qqplots-on-one-gragh-and-single-abline-ggplot2-r%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
Straightforward in ggplot2
with stat_qq
and reshaping your data from wide to long.
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot <- dat %>%
gather(variable, value, -Observed) %>%
ggplot(aes(sample = value, color = variable)) +
geom_abline() +
stat_qq()
# All in one
plot
It might be beneficial if you look at making facets or small multiples along your comparison variable.
# Facets!
plot +
facet_wrap(~variable)
If you're looking to provide your own observed, then rather than being fancy, let qqplot
do the heavy lifting but set plot.it = FALSE
and it will return you a list of x/y coords for the qq plot. A little iteration with purrr::map_dfr
, and you can do:
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1 = rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot_data <- map_dfr(names(dat)[-1], ~as_tibble(qqplot(dat[[.x]], dat$Observed, plot.it = FALSE)) %>%
mutate(id = .x))
ggplot(plot_data, aes(x, y, color = id)) +
geom_point() +
geom_abline() +
facet_wrap(~id)
Created on 2018-11-25 by the reprex package (v0.2.1)
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
stat_qq
andgeom_qq
seem to seem to be designed to compare one or more vectorse.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors,e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but inggplot2
? Thank you.
– code123
Nov 25 '18 at 18:44
This is where you would conduct your comparison outside of ggplot, then just usegeom_point
to plot your expected vs observed.
– Jake Kaupp
Nov 25 '18 at 21:33
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
1
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
|
show 1 more comment
Straightforward in ggplot2
with stat_qq
and reshaping your data from wide to long.
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot <- dat %>%
gather(variable, value, -Observed) %>%
ggplot(aes(sample = value, color = variable)) +
geom_abline() +
stat_qq()
# All in one
plot
It might be beneficial if you look at making facets or small multiples along your comparison variable.
# Facets!
plot +
facet_wrap(~variable)
If you're looking to provide your own observed, then rather than being fancy, let qqplot
do the heavy lifting but set plot.it = FALSE
and it will return you a list of x/y coords for the qq plot. A little iteration with purrr::map_dfr
, and you can do:
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1 = rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot_data <- map_dfr(names(dat)[-1], ~as_tibble(qqplot(dat[[.x]], dat$Observed, plot.it = FALSE)) %>%
mutate(id = .x))
ggplot(plot_data, aes(x, y, color = id)) +
geom_point() +
geom_abline() +
facet_wrap(~id)
Created on 2018-11-25 by the reprex package (v0.2.1)
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
stat_qq
andgeom_qq
seem to seem to be designed to compare one or more vectorse.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors,e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but inggplot2
? Thank you.
– code123
Nov 25 '18 at 18:44
This is where you would conduct your comparison outside of ggplot, then just usegeom_point
to plot your expected vs observed.
– Jake Kaupp
Nov 25 '18 at 21:33
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
1
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
|
show 1 more comment
Straightforward in ggplot2
with stat_qq
and reshaping your data from wide to long.
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot <- dat %>%
gather(variable, value, -Observed) %>%
ggplot(aes(sample = value, color = variable)) +
geom_abline() +
stat_qq()
# All in one
plot
It might be beneficial if you look at making facets or small multiples along your comparison variable.
# Facets!
plot +
facet_wrap(~variable)
If you're looking to provide your own observed, then rather than being fancy, let qqplot
do the heavy lifting but set plot.it = FALSE
and it will return you a list of x/y coords for the qq plot. A little iteration with purrr::map_dfr
, and you can do:
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1 = rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot_data <- map_dfr(names(dat)[-1], ~as_tibble(qqplot(dat[[.x]], dat$Observed, plot.it = FALSE)) %>%
mutate(id = .x))
ggplot(plot_data, aes(x, y, color = id)) +
geom_point() +
geom_abline() +
facet_wrap(~id)
Created on 2018-11-25 by the reprex package (v0.2.1)
Straightforward in ggplot2
with stat_qq
and reshaping your data from wide to long.
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1= rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot <- dat %>%
gather(variable, value, -Observed) %>%
ggplot(aes(sample = value, color = variable)) +
geom_abline() +
stat_qq()
# All in one
plot
It might be beneficial if you look at making facets or small multiples along your comparison variable.
# Facets!
plot +
facet_wrap(~variable)
If you're looking to provide your own observed, then rather than being fancy, let qqplot
do the heavy lifting but set plot.it = FALSE
and it will return you a list of x/y coords for the qq plot. A little iteration with purrr::map_dfr
, and you can do:
library(tidyverse)
set.seed(10)
dat <- data.frame(Observed = rnorm(20), sim1 = rnorm(20), sim2 = rnorm(20),sim3 = rnorm(20),sim4 = rnorm(20),sim5 = rnorm(20),sim6 = rnorm(20))
plot_data <- map_dfr(names(dat)[-1], ~as_tibble(qqplot(dat[[.x]], dat$Observed, plot.it = FALSE)) %>%
mutate(id = .x))
ggplot(plot_data, aes(x, y, color = id)) +
geom_point() +
geom_abline() +
facet_wrap(~id)
Created on 2018-11-25 by the reprex package (v0.2.1)
edited Nov 26 '18 at 1:11
answered Nov 23 '18 at 20:44
Jake KauppJake Kaupp
5,64721428
5,64721428
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
stat_qq
andgeom_qq
seem to seem to be designed to compare one or more vectorse.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors,e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but inggplot2
? Thank you.
– code123
Nov 25 '18 at 18:44
This is where you would conduct your comparison outside of ggplot, then just usegeom_point
to plot your expected vs observed.
– Jake Kaupp
Nov 25 '18 at 21:33
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
1
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
|
show 1 more comment
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
stat_qq
andgeom_qq
seem to seem to be designed to compare one or more vectorse.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors,e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but inggplot2
? Thank you.
– code123
Nov 25 '18 at 18:44
This is where you would conduct your comparison outside of ggplot, then just usegeom_point
to plot your expected vs observed.
– Jake Kaupp
Nov 25 '18 at 21:33
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
1
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
Awesome! Thank you @Jake Kaupp
– code123
Nov 23 '18 at 20:49
stat_qq
and geom_qq
seem to seem to be designed to compare one or more vectors e.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors, e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but in ggplot2
? Thank you.– code123
Nov 25 '18 at 18:44
stat_qq
and geom_qq
seem to seem to be designed to compare one or more vectors e.g. sim1-6 vector
to a theoretical distribution, I couldn't see how to use it to compare two different vectors, e.g each of sim1 to sim6 compared against Observed?
How can I do exactly what I specified in the link under my question but in ggplot2
? Thank you.– code123
Nov 25 '18 at 18:44
This is where you would conduct your comparison outside of ggplot, then just use
geom_point
to plot your expected vs observed.– Jake Kaupp
Nov 25 '18 at 21:33
This is where you would conduct your comparison outside of ggplot, then just use
geom_point
to plot your expected vs observed.– Jake Kaupp
Nov 25 '18 at 21:33
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
I guess an example with the sample data will shed more light on the problem better?
– code123
Nov 25 '18 at 21:43
1
1
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
Updated the answer to address providing your own observed values.
– Jake Kaupp
Nov 26 '18 at 1:12
|
show 1 more 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%2f53452588%2fmultiple-qqplots-on-one-gragh-and-single-abline-ggplot2-r%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