fill area between two lines with different x-values
I have a data frame with two columns xs and ys. Each row represents a line and in each cell is a list with 51 consecutive observations (so 2 lists in each row for x and y!).
I want to fill the space between the lines in the data frame.
the problem is that there's a randomness in x and y, so I can't just take the ymin and ymax for each data point on x.
this would create similarly shaped data (with only 2 lines with 10 observations):
genData <- function()
set.seed(42)
genOneLine <- function(m_x, m_y)
xs = seq(0,1,by=0.1)
x_ran <- rnorm(8, m_x, 0.1)
xs[2:9] = xs[2:9] + x_ran
ys = seq(0,1,by=0.1)
y_ran <- rnorm(8, m_y, 0.1)
ys[2:9] = ys[2:9] + y_ran
return (data.table(x = list(xs), y = list(ys)))
return (rbind(genOneLine(-0.1, -0.1), genOneLine(0.1, 0.1)))
r ggplot2 plot
add a comment |
I have a data frame with two columns xs and ys. Each row represents a line and in each cell is a list with 51 consecutive observations (so 2 lists in each row for x and y!).
I want to fill the space between the lines in the data frame.
the problem is that there's a randomness in x and y, so I can't just take the ymin and ymax for each data point on x.
this would create similarly shaped data (with only 2 lines with 10 observations):
genData <- function()
set.seed(42)
genOneLine <- function(m_x, m_y)
xs = seq(0,1,by=0.1)
x_ran <- rnorm(8, m_x, 0.1)
xs[2:9] = xs[2:9] + x_ran
ys = seq(0,1,by=0.1)
y_ran <- rnorm(8, m_y, 0.1)
ys[2:9] = ys[2:9] + y_ran
return (data.table(x = list(xs), y = list(ys)))
return (rbind(genOneLine(-0.1, -0.1), genOneLine(0.1, 0.1)))
r ggplot2 plot
5
You may not be able to share your real data, but surely you can throw together some example data? Say, ~10 rows with similar structure and properties as your real data to demonstrate the problem? See here for advice on creating reproducible examples. Useset.seed
to make any randomness reproducible.
– Gregor
Nov 13 '18 at 20:22
What do you mean "fill the space between the lines in the data frame"? Do you mean something about plotting the data or interpolating?
– G5W
Nov 13 '18 at 20:26
sure, I can throw together some example data! I thought it was more or less clear, but it probalby helps. I'll update the question in a few minutes
– Leander
Nov 13 '18 at 20:44
I have updated the question
– Leander
Nov 13 '18 at 21:05
add a comment |
I have a data frame with two columns xs and ys. Each row represents a line and in each cell is a list with 51 consecutive observations (so 2 lists in each row for x and y!).
I want to fill the space between the lines in the data frame.
the problem is that there's a randomness in x and y, so I can't just take the ymin and ymax for each data point on x.
this would create similarly shaped data (with only 2 lines with 10 observations):
genData <- function()
set.seed(42)
genOneLine <- function(m_x, m_y)
xs = seq(0,1,by=0.1)
x_ran <- rnorm(8, m_x, 0.1)
xs[2:9] = xs[2:9] + x_ran
ys = seq(0,1,by=0.1)
y_ran <- rnorm(8, m_y, 0.1)
ys[2:9] = ys[2:9] + y_ran
return (data.table(x = list(xs), y = list(ys)))
return (rbind(genOneLine(-0.1, -0.1), genOneLine(0.1, 0.1)))
r ggplot2 plot
I have a data frame with two columns xs and ys. Each row represents a line and in each cell is a list with 51 consecutive observations (so 2 lists in each row for x and y!).
I want to fill the space between the lines in the data frame.
the problem is that there's a randomness in x and y, so I can't just take the ymin and ymax for each data point on x.
this would create similarly shaped data (with only 2 lines with 10 observations):
genData <- function()
set.seed(42)
genOneLine <- function(m_x, m_y)
xs = seq(0,1,by=0.1)
x_ran <- rnorm(8, m_x, 0.1)
xs[2:9] = xs[2:9] + x_ran
ys = seq(0,1,by=0.1)
y_ran <- rnorm(8, m_y, 0.1)
ys[2:9] = ys[2:9] + y_ran
return (data.table(x = list(xs), y = list(ys)))
return (rbind(genOneLine(-0.1, -0.1), genOneLine(0.1, 0.1)))
r ggplot2 plot
r ggplot2 plot
edited Nov 13 '18 at 21:05
Leander
asked Nov 13 '18 at 20:18
LeanderLeander
570819
570819
5
You may not be able to share your real data, but surely you can throw together some example data? Say, ~10 rows with similar structure and properties as your real data to demonstrate the problem? See here for advice on creating reproducible examples. Useset.seed
to make any randomness reproducible.
– Gregor
Nov 13 '18 at 20:22
What do you mean "fill the space between the lines in the data frame"? Do you mean something about plotting the data or interpolating?
– G5W
Nov 13 '18 at 20:26
sure, I can throw together some example data! I thought it was more or less clear, but it probalby helps. I'll update the question in a few minutes
– Leander
Nov 13 '18 at 20:44
I have updated the question
– Leander
Nov 13 '18 at 21:05
add a comment |
5
You may not be able to share your real data, but surely you can throw together some example data? Say, ~10 rows with similar structure and properties as your real data to demonstrate the problem? See here for advice on creating reproducible examples. Useset.seed
to make any randomness reproducible.
– Gregor
Nov 13 '18 at 20:22
What do you mean "fill the space between the lines in the data frame"? Do you mean something about plotting the data or interpolating?
– G5W
Nov 13 '18 at 20:26
sure, I can throw together some example data! I thought it was more or less clear, but it probalby helps. I'll update the question in a few minutes
– Leander
Nov 13 '18 at 20:44
I have updated the question
– Leander
Nov 13 '18 at 21:05
5
5
You may not be able to share your real data, but surely you can throw together some example data? Say, ~10 rows with similar structure and properties as your real data to demonstrate the problem? See here for advice on creating reproducible examples. Use
set.seed
to make any randomness reproducible.– Gregor
Nov 13 '18 at 20:22
You may not be able to share your real data, but surely you can throw together some example data? Say, ~10 rows with similar structure and properties as your real data to demonstrate the problem? See here for advice on creating reproducible examples. Use
set.seed
to make any randomness reproducible.– Gregor
Nov 13 '18 at 20:22
What do you mean "fill the space between the lines in the data frame"? Do you mean something about plotting the data or interpolating?
– G5W
Nov 13 '18 at 20:26
What do you mean "fill the space between the lines in the data frame"? Do you mean something about plotting the data or interpolating?
– G5W
Nov 13 '18 at 20:26
sure, I can throw together some example data! I thought it was more or less clear, but it probalby helps. I'll update the question in a few minutes
– Leander
Nov 13 '18 at 20:44
sure, I can throw together some example data! I thought it was more or less clear, but it probalby helps. I'll update the question in a few minutes
– Leander
Nov 13 '18 at 20:44
I have updated the question
– Leander
Nov 13 '18 at 21:05
I have updated the question
– Leander
Nov 13 '18 at 21:05
add a comment |
0
active
oldest
votes
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%2f53288871%2ffill-area-between-two-lines-with-different-x-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53288871%2ffill-area-between-two-lines-with-different-x-values%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
5
You may not be able to share your real data, but surely you can throw together some example data? Say, ~10 rows with similar structure and properties as your real data to demonstrate the problem? See here for advice on creating reproducible examples. Use
set.seed
to make any randomness reproducible.– Gregor
Nov 13 '18 at 20:22
What do you mean "fill the space between the lines in the data frame"? Do you mean something about plotting the data or interpolating?
– G5W
Nov 13 '18 at 20:26
sure, I can throw together some example data! I thought it was more or less clear, but it probalby helps. I'll update the question in a few minutes
– Leander
Nov 13 '18 at 20:44
I have updated the question
– Leander
Nov 13 '18 at 21:05