fill area between two lines with different x-values
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 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 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 at 20:44
I have updated the question
– Leander
Nov 13 at 21:05
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 at 21:05
asked Nov 13 at 20:18
Leander
553719
553719
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 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 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 at 20:44
I have updated the question
– Leander
Nov 13 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 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 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 at 20:44
I have updated the question
– Leander
Nov 13 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 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 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 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 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 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 at 20:44
I have updated the question
– Leander
Nov 13 at 21:05
I have updated the question
– Leander
Nov 13 at 21:05
add a comment |
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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 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 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 at 20:44
I have updated the question
– Leander
Nov 13 at 21:05