Plot overlaps of time intervals The Next CEO of Stack OverflowRemove rows with all or some NAs (missing values) in data.frameFind all date ranges for overlapping start and end dates in RSide-by-side plots with ggplot2Plot two graphs in same plot in RHow to set limits for axes in ggplot2 R plots?Plotting two variables as lines using ggplot2 on the same graphHow to save a plot as image on the disk?R - plot overlapping time intervalsMultiple geom_rect over a time seriesCenter Plot title in ggplot2calculate and plot time interval meansFinding the time interval in which a date occurs

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Ising model simulation

Yu-Gi-Oh cards in Python 3

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Is it professional to write unrelated content in an almost-empty email?

Inductor and Capacitor in Parallel

Can Sneak Attack be used when hitting with an improvised weapon?

Does higher Oxidation/ reduction potential translate to higher energy storage in battery?

How to avoid supervisors with prejudiced views?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

How can the PCs determine if an item is a phylactery?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Could a dragon use its wings to swim?

Reshaping json / reparing json inside shell script (remove trailing comma)

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

Towers in the ocean; How deep can they be built?

TikZ: How to fill area with a special pattern?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Is it okay to majorly distort historical facts while writing a fiction story?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Airplane gently rocking its wings during whole flight

Strange use of "whether ... than ..." in official text

Is Nisuin Biblical or Rabbinic?



Plot overlaps of time intervals



The Next CEO of Stack OverflowRemove rows with all or some NAs (missing values) in data.frameFind all date ranges for overlapping start and end dates in RSide-by-side plots with ggplot2Plot two graphs in same plot in RHow to set limits for axes in ggplot2 R plots?Plotting two variables as lines using ggplot2 on the same graphHow to save a plot as image on the disk?R - plot overlapping time intervalsMultiple geom_rect over a time seriesCenter Plot title in ggplot2calculate and plot time interval meansFinding the time interval in which a date occurs










1















I have the following df



Id a_min_date a_max_date b_min_date b_max_date c_min_date c_max_date d_min_date a_max_date
1 2014-01-01 2014-01-10 2014-01-05 2014-01-15 NA NA 2014-02-20 2014-05-01
2 2014-02-01 2014-02-10 NA NA 2015-02-20 2015-03-01 NA NA


I have added the intervals of each group (a, b, c,d) by ID. First, I have converted the start and end dates to lubridate intervals.
I want to plot the intervals and calculate the time difference in days between the end of each group and the start of next group if there is no overlap.
I tried to use IRanges package and converted the dates into integers (as used here (link)), but does not work for me.



ir <- IRanges::IRanges(start = as.integer((as.Date(df$a_min_date))), end = as.integer((as.Date(df$a_max_date))))
bins <- disjointBins(IRanges(start(ir), end(ir) + 1))
dat <- cbind(as.data.frame(ir), bin = bins)

ggplot(dat) +
geom_rect(aes(xmin = start, xmax = end,
ymin = bin, ymax = bin + 0.9)) +
theme_bw()


I got this error for my orginal df:



Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
solving row 1: range cannot be determined from the supplied arguments (too many NAs)


Does someone have another solution using other packages?










share|improve this question
























  • Could you please provide a sample of the output?

    – akash87
    Mar 21 at 19:13











  • The figure that ggplo2 has created was empty. I have no real output. I want just to plot this intervals and see if there is any overlap.

    – A1976
    Mar 21 at 19:21
















1















I have the following df



Id a_min_date a_max_date b_min_date b_max_date c_min_date c_max_date d_min_date a_max_date
1 2014-01-01 2014-01-10 2014-01-05 2014-01-15 NA NA 2014-02-20 2014-05-01
2 2014-02-01 2014-02-10 NA NA 2015-02-20 2015-03-01 NA NA


I have added the intervals of each group (a, b, c,d) by ID. First, I have converted the start and end dates to lubridate intervals.
I want to plot the intervals and calculate the time difference in days between the end of each group and the start of next group if there is no overlap.
I tried to use IRanges package and converted the dates into integers (as used here (link)), but does not work for me.



ir <- IRanges::IRanges(start = as.integer((as.Date(df$a_min_date))), end = as.integer((as.Date(df$a_max_date))))
bins <- disjointBins(IRanges(start(ir), end(ir) + 1))
dat <- cbind(as.data.frame(ir), bin = bins)

ggplot(dat) +
geom_rect(aes(xmin = start, xmax = end,
ymin = bin, ymax = bin + 0.9)) +
theme_bw()


I got this error for my orginal df:



Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
solving row 1: range cannot be determined from the supplied arguments (too many NAs)


Does someone have another solution using other packages?










share|improve this question
























  • Could you please provide a sample of the output?

    – akash87
    Mar 21 at 19:13











  • The figure that ggplo2 has created was empty. I have no real output. I want just to plot this intervals and see if there is any overlap.

    – A1976
    Mar 21 at 19:21














1












1








1








I have the following df



Id a_min_date a_max_date b_min_date b_max_date c_min_date c_max_date d_min_date a_max_date
1 2014-01-01 2014-01-10 2014-01-05 2014-01-15 NA NA 2014-02-20 2014-05-01
2 2014-02-01 2014-02-10 NA NA 2015-02-20 2015-03-01 NA NA


I have added the intervals of each group (a, b, c,d) by ID. First, I have converted the start and end dates to lubridate intervals.
I want to plot the intervals and calculate the time difference in days between the end of each group and the start of next group if there is no overlap.
I tried to use IRanges package and converted the dates into integers (as used here (link)), but does not work for me.



ir <- IRanges::IRanges(start = as.integer((as.Date(df$a_min_date))), end = as.integer((as.Date(df$a_max_date))))
bins <- disjointBins(IRanges(start(ir), end(ir) + 1))
dat <- cbind(as.data.frame(ir), bin = bins)

ggplot(dat) +
geom_rect(aes(xmin = start, xmax = end,
ymin = bin, ymax = bin + 0.9)) +
theme_bw()


I got this error for my orginal df:



Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
solving row 1: range cannot be determined from the supplied arguments (too many NAs)


Does someone have another solution using other packages?










share|improve this question
















I have the following df



Id a_min_date a_max_date b_min_date b_max_date c_min_date c_max_date d_min_date a_max_date
1 2014-01-01 2014-01-10 2014-01-05 2014-01-15 NA NA 2014-02-20 2014-05-01
2 2014-02-01 2014-02-10 NA NA 2015-02-20 2015-03-01 NA NA


I have added the intervals of each group (a, b, c,d) by ID. First, I have converted the start and end dates to lubridate intervals.
I want to plot the intervals and calculate the time difference in days between the end of each group and the start of next group if there is no overlap.
I tried to use IRanges package and converted the dates into integers (as used here (link)), but does not work for me.



ir <- IRanges::IRanges(start = as.integer((as.Date(df$a_min_date))), end = as.integer((as.Date(df$a_max_date))))
bins <- disjointBins(IRanges(start(ir), end(ir) + 1))
dat <- cbind(as.data.frame(ir), bin = bins)

ggplot(dat) +
geom_rect(aes(xmin = start, xmax = end,
ymin = bin, ymax = bin + 0.9)) +
theme_bw()


I got this error for my orginal df:



Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
solving row 1: range cannot be determined from the supplied arguments (too many NAs)


Does someone have another solution using other packages?







r ggplot2 dplyr iranges






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 19:20







A1976

















asked Mar 21 at 19:09









A1976A1976

246




246












  • Could you please provide a sample of the output?

    – akash87
    Mar 21 at 19:13











  • The figure that ggplo2 has created was empty. I have no real output. I want just to plot this intervals and see if there is any overlap.

    – A1976
    Mar 21 at 19:21


















  • Could you please provide a sample of the output?

    – akash87
    Mar 21 at 19:13











  • The figure that ggplo2 has created was empty. I have no real output. I want just to plot this intervals and see if there is any overlap.

    – A1976
    Mar 21 at 19:21

















Could you please provide a sample of the output?

– akash87
Mar 21 at 19:13





Could you please provide a sample of the output?

– akash87
Mar 21 at 19:13













The figure that ggplo2 has created was empty. I have no real output. I want just to plot this intervals and see if there is any overlap.

– A1976
Mar 21 at 19:21






The figure that ggplo2 has created was empty. I have no real output. I want just to plot this intervals and see if there is any overlap.

– A1976
Mar 21 at 19:21













1 Answer
1






active

oldest

votes


















0














To my knowledge, IRanges is the best package out there to solve this problem.
IRanges needs range values (in this case dates) to compare and does not handle undefined values (NAs)



To solve this problem, I would remove all rows with NAs in df before doing the analysis.



df <- df[complete.cases(df[ , 1:2]),]


Explanation and other ways to remove NAs see Remove rows with all or some NAs (missing values) in data.frame.



If this does not fix the problem, you could convert the dates into integers. Important there is that the dates have the year-month-day format to result in correct intervals.



Example:



str <- "2006-06-26"


splitted<- unlist(strsplit(str,"-"))
[1] "2006" "06" "26"

result <- paste(splitted,collapse="")
[1] "20060626"





share|improve this answer

























  • I have exclude NAs, but did not help. Is there any other method using dplyr?

    – A1976
    Mar 21 at 23:44











  • I would simply convert the strings to integer for analysis (see example in my modified answer).

    – scs
    Mar 22 at 8:54











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287676%2fplot-overlaps-of-time-intervals%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









0














To my knowledge, IRanges is the best package out there to solve this problem.
IRanges needs range values (in this case dates) to compare and does not handle undefined values (NAs)



To solve this problem, I would remove all rows with NAs in df before doing the analysis.



df <- df[complete.cases(df[ , 1:2]),]


Explanation and other ways to remove NAs see Remove rows with all or some NAs (missing values) in data.frame.



If this does not fix the problem, you could convert the dates into integers. Important there is that the dates have the year-month-day format to result in correct intervals.



Example:



str <- "2006-06-26"


splitted<- unlist(strsplit(str,"-"))
[1] "2006" "06" "26"

result <- paste(splitted,collapse="")
[1] "20060626"





share|improve this answer

























  • I have exclude NAs, but did not help. Is there any other method using dplyr?

    – A1976
    Mar 21 at 23:44











  • I would simply convert the strings to integer for analysis (see example in my modified answer).

    – scs
    Mar 22 at 8:54















0














To my knowledge, IRanges is the best package out there to solve this problem.
IRanges needs range values (in this case dates) to compare and does not handle undefined values (NAs)



To solve this problem, I would remove all rows with NAs in df before doing the analysis.



df <- df[complete.cases(df[ , 1:2]),]


Explanation and other ways to remove NAs see Remove rows with all or some NAs (missing values) in data.frame.



If this does not fix the problem, you could convert the dates into integers. Important there is that the dates have the year-month-day format to result in correct intervals.



Example:



str <- "2006-06-26"


splitted<- unlist(strsplit(str,"-"))
[1] "2006" "06" "26"

result <- paste(splitted,collapse="")
[1] "20060626"





share|improve this answer

























  • I have exclude NAs, but did not help. Is there any other method using dplyr?

    – A1976
    Mar 21 at 23:44











  • I would simply convert the strings to integer for analysis (see example in my modified answer).

    – scs
    Mar 22 at 8:54













0












0








0







To my knowledge, IRanges is the best package out there to solve this problem.
IRanges needs range values (in this case dates) to compare and does not handle undefined values (NAs)



To solve this problem, I would remove all rows with NAs in df before doing the analysis.



df <- df[complete.cases(df[ , 1:2]),]


Explanation and other ways to remove NAs see Remove rows with all or some NAs (missing values) in data.frame.



If this does not fix the problem, you could convert the dates into integers. Important there is that the dates have the year-month-day format to result in correct intervals.



Example:



str <- "2006-06-26"


splitted<- unlist(strsplit(str,"-"))
[1] "2006" "06" "26"

result <- paste(splitted,collapse="")
[1] "20060626"





share|improve this answer















To my knowledge, IRanges is the best package out there to solve this problem.
IRanges needs range values (in this case dates) to compare and does not handle undefined values (NAs)



To solve this problem, I would remove all rows with NAs in df before doing the analysis.



df <- df[complete.cases(df[ , 1:2]),]


Explanation and other ways to remove NAs see Remove rows with all or some NAs (missing values) in data.frame.



If this does not fix the problem, you could convert the dates into integers. Important there is that the dates have the year-month-day format to result in correct intervals.



Example:



str <- "2006-06-26"


splitted<- unlist(strsplit(str,"-"))
[1] "2006" "06" "26"

result <- paste(splitted,collapse="")
[1] "20060626"






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 8:53

























answered Mar 21 at 19:46









scsscs

151116




151116












  • I have exclude NAs, but did not help. Is there any other method using dplyr?

    – A1976
    Mar 21 at 23:44











  • I would simply convert the strings to integer for analysis (see example in my modified answer).

    – scs
    Mar 22 at 8:54

















  • I have exclude NAs, but did not help. Is there any other method using dplyr?

    – A1976
    Mar 21 at 23:44











  • I would simply convert the strings to integer for analysis (see example in my modified answer).

    – scs
    Mar 22 at 8:54
















I have exclude NAs, but did not help. Is there any other method using dplyr?

– A1976
Mar 21 at 23:44





I have exclude NAs, but did not help. Is there any other method using dplyr?

– A1976
Mar 21 at 23:44













I would simply convert the strings to integer for analysis (see example in my modified answer).

– scs
Mar 22 at 8:54





I would simply convert the strings to integer for analysis (see example in my modified answer).

– scs
Mar 22 at 8:54



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287676%2fplot-overlaps-of-time-intervals%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현