{"id":19453,"date":"2022-11-06T18:46:00","date_gmt":"2022-11-06T13:16:00","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/"},"modified":"2022-11-06T18:46:00","modified_gmt":"2022-11-06T13:16:00","slug":"solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/","title":{"rendered":"[Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-10723235\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"10723235\" data-parentid=\"10671167\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Ok I finally found it. <\/p>\n<p>On the x axis I wanted to plot dates either as POSIXct or as number of day of recording (integer). On the y axis I wanted the time of day so that the graph would present a dark bar on each day (x-axis) and between the time (y-axis) that the episode take place.<\/p>\n<p>R can plot POSIX, but in my case the episode start and end time (for the y-axis) should be date-&#8220;less&#8221;<\/p>\n<p>I did this like this<\/p>\n<pre><code>#Cleaning the Dataset\nqs&lt;-question.stack\nqs$id&lt;-as.character(qs$id)\nqs$begin.recording&lt;-as.character(qs$begin.recording)\nqs$begin.of.episode&lt;-as.character(qs$begin.of.episode)\nqs$start.time&lt;-as.character(qs$start.time)\nqs$start&lt;-as.character(paste(qs$begin.of.episode,qs$start.time))\nqs$duration&lt;-round(qs$duration,0)\n\n#Convert time and dates to POSIXct\nqs$start&lt;-as.POSIXct(qs$start,format=\"%m\/%d\/%Y %H:%M:%S\",tz=\"UTC\")\nqs$start&lt;-round(qs$start,\"mins\")\nqs$end&lt;-as.POSIXct(qs$start+qs$duration*60)\nqs$start&lt;-as.POSIXct(qs$start)\n<\/code><\/pre>\n<p>Now we have<\/p>\n<pre><code>str(qs)\n'data.frame':   398 obs. of  8 variables:\n $ id              : chr  \"AA11\" \"AA11\" \"AA11\" \"AA11\" ...\n $ begin.recording : chr  \"8\/15\/2007\" \"8\/15\/2007\" \"8\/15\/2007\" \"8\/15\/2007\" ...\n $ begin.of.episode: chr  \"8\/27\/2007\" \"8\/27\/2007\" \"8\/27\/2007\" \"8\/28\/2007\" ...\n $ episode.day     : int  12 12 12 13 14 15 15 17 17 18 ...\n $ start.time      : chr  \"6:15:12\" \"10:55:12\" \"11:15:12\" \"18:19:12\" ...\n $ duration        : num  278 14 1324 18 428 ...\n $ start           : POSIXct, format: \"2007-08-27 06:15:00\" \"2007-08-27 10:55:00\" ...\n $ end             : POSIXct, format: \"2007-08-27 10:53:00\" \"2007-08-27 11:09:00\" ...\n<\/code><\/pre>\n<p>The following makes a vector which includes all minutes that there was an episode. One can fine tune it by seconds or upscale it by hours<\/p>\n<pre><code>tmp&lt;-do.call(c, apply(qs, 1, function(x) seq(from=as.POSIXct(x[7]), to=as.POSIXct(x[8]),by=\"mins\")))\n<\/code><\/pre>\n<p>The following makes a data frame. The switch of the time of day from POSIX to (date-&#8220;less&#8221;) and then back to POSIX garantees that there will be the same date in all times of time.of.day. Perhaps one can also do it with the origin argument.<\/p>\n<pre><code>ep &lt;- data.frame(sqs=tmp, date=as.Date(tmp,\"%Y-%m-%d\"),time.of.day=as.POSIXct(as.character(format(tmp,\"%H:%M\")),format=\"%H:%M\"))\n<\/code><\/pre>\n<p>Plot<\/p>\n<pre><code>plot(ep$date, ep$time.of.day,pch=\".\")\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png\" alt=\"enter image description here\"><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Plot time(x axis) and time of day &#038; duration(y axis) of episodes <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Ok I finally found it. On the x axis I wanted to plot dates either as POSIXct or as number of day of recording (integer). On the y axis I wanted the time of day so that the graph would present a dark bar on each day (x-axis) and between the time (y-axis) that &#8230; <a title=\"[Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\" aria-label=\"More on [Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[433,771,321,636,1707],"class_list":["post-19453","post","type-post","status-publish","format-standard","hentry","category-solved","tag-date","tag-graph","tag-r","tag-time","tag-time-series"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Plot time(x axis) and time of day &amp; duration(y axis) of episodes - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Plot time(x axis) and time of day &amp; duration(y axis) of episodes - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Ok I finally found it. On the x axis I wanted to plot dates either as POSIXct or as number of day of recording (integer). On the y axis I wanted the time of day so that the graph would present a dark bar on each day (x-axis) and between the time (y-axis) that ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-06T13:16:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes\",\"datePublished\":\"2022-11-06T13:16:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\"},\"wordCount\":192,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png\",\"keywords\":[\"date\",\"graph\",\"r\",\"time\",\"time-series\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\",\"name\":\"[Solved] Plot time(x axis) and time of day & duration(y axis) of episodes - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png\",\"datePublished\":\"2022-11-06T13:16:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Plot time(x axis) and time of day & duration(y axis) of episodes - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Plot time(x axis) and time of day & duration(y axis) of episodes - JassWeb","og_description":"[ad_1] Ok I finally found it. On the x axis I wanted to plot dates either as POSIXct or as number of day of recording (integer). On the y axis I wanted the time of day so that the graph would present a dark bar on each day (x-axis) and between the time (y-axis) that ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/","og_site_name":"JassWeb","article_published_time":"2022-11-06T13:16:00+00:00","og_image":[{"url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png","type":"","width":"","height":""}],"author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes","datePublished":"2022-11-06T13:16:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/"},"wordCount":192,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png","keywords":["date","graph","r","time","time-series"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/","url":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/","name":"[Solved] Plot time(x axis) and time of day & duration(y axis) of episodes - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png","datePublished":"2022-11-06T13:16:00+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#primaryimage","url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Plot-timex-axis-and-time-of-day-durationy.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-plot-timex-axis-and-time-of-day-durationy-axis-of-episodes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Plot time(x axis) and time of day &#038; duration(y axis) of episodes"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/19453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=19453"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/19453\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=19453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=19453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=19453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}