{"id":211890,"date":"2024-09-12T12:31:12","date_gmt":"2024-09-12T16:31:12","guid":{"rendered":"https:\/\/ibkrcampus.com\/campus\/?p=211890"},"modified":"2025-02-12T10:09:15","modified_gmt":"2025-02-12T15:09:15","slug":"r-code-setting-x-axis-as-the-selected-dates","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/","title":{"rendered":"R Code: Setting X-Axis As The Selected Dates"},"content":{"rendered":"\n<p><em>Originally posted on <a href=\"https:\/\/shleeai.blogspot.com\/2022\/10\/r-code-setting-x-axis-as-selected-dates.html\">SHLee AI Financial Model<\/a> blog.<\/em><\/p>\n\n\n\n<p><strong><em>Excerpt<\/em><\/strong><\/p>\n\n\n\n<p>This post shows a simple R code to&nbsp;<strong>set x-axis as some selected dates<\/strong>&nbsp;rather than using 1, 2, 3, &#8230; on x-axis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-set-x-axis-with-some-selected-dates\">set x-axis with some selected dates<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-match-or-which-in\">match() or which( %in% )<\/h3>\n\n\n\n<p>To find positions in one array of the values in the other array,&nbsp;<strong>match()<\/strong>&nbsp;or&nbsp;<strong>which( %in% )<\/strong>&nbsp;can be used. The former is applied to a unique set and the latter to a redundant set.<\/p>\n\n\n\n<p>In other words,&nbsp;<strong>match()<\/strong>&nbsp;only returns the first occurrence of a match.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#-----------------------------------\n# match() or which( %in% )\n#-----------------------------------\ny &lt;- c(10,20,30,40,50,60,70,80,90,100)\nx &lt;- c(10,30,50,70,90)\n \n# for unique dataset\n \nmatch(x,y)\n# [1] 1 3 5 7 9\n \ny[match(x,y)]\n# [1] 10 30 50 70 90\n \n# for redundant dataset\n \nwhich(y %in% x)\n# [1] 1 3 5 7 9\n \ny[which(y %in% x)]\n# [1] 10 30 50 70 90<\/pre>\n\n\n\n<p>Unlike&nbsp;<strong>match()<\/strong>,&nbsp;<strong>which( %in% )<\/strong>&nbsp;returns the multiple encounters of a match. Here 90 appears twice.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#-----------------------------------\n# match() or which( %in% )\n#-----------------------------------\ny &lt;- c(10,20,30,40,50,60,70,80,90,90,100)\nx &lt;- c(10,30,50,70,90)\n \n# for unique dataset\n \nmatch(x,y)\n# [1] 1 3 5 7 9\n \ny[match(x,y)]\n# [1] 10 30 50 70 90\n \n# for redundant dataset\n \nwhich(y %in% x)\n# [1] 1  3  5  7  9 10\n \ny[which(y %in% x)]\n# [1] 10 30 50 70 90 90<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Finding the selected dates from the whole dates<\/h3>\n\n\n\n<p>A set of dates is unique so that&nbsp;<strong>match()<\/strong>&nbsp;function is used. In this example, the last dates for each year (<strong>vdate_last<\/strong>) are selected from the whole set of dates (<strong>vdate<\/strong>). These selected dates are located at an index set (<strong>idx_last<\/strong>).<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#-----------------------------------\n# sample input for dates\n#-----------------------------------\nstr_vdate &lt;- \"\n    2001-01-31 \n    2001-02-28 2001-03-30 \n    2001-04-30 2001-05-31 2001-06-29 \n    2001-07-31 2001-08-31 2001-09-28 2001-10-31\n    2001-11-30 2001-12-31 2002-01-31 2002-02-28 2002-03-28\n    2002-04-30 2002-05-31 2002-06-28 2002-07-31 2002-08-30\n    2002-09-30 2002-10-31 2002-11-29 2002-12-31 2003-01-31\n    2003-02-28 2003-03-31 2003-04-30 2003-05-30 2003-06-30\n    2003-07-31 2003-08-29 2003-09-30 2003-10-31 2003-11-28\n    2003-12-31 2004-01-30 2004-02-27 2004-03-31 2004-04-30\n    2004-05-28 2004-06-30 2004-07-30 2004-08-31 2004-09-30\n    2004-10-29 2004-11-30 2004-12-31 2005-01-31 2005-02-28\n    2005-03-31 2005-04-29 2005-05-31 2005-06-30 2005-07-29\n    2005-08-31 2005-09-30 2005-10-31 2005-11-30 2005-12-30\n    2006-01-31 2006-02-28 2006-03-31 2006-04-28 2006-05-31\n    2006-06-30 2006-07-31 2006-08-31 2006-09-29 2006-10-31\n    2006-11-30 2006-12-29 2007-01-31 2007-02-28 2007-03-30\n    2007-04-30 2007-05-31 2007-06-29 2007-07-31 2007-08-31\n    2007-09-28 2007-10-31 2007-11-30 2007-12-31 2008-01-31\n    2008-02-29 2008-03-31 2008-04-30 2008-05-30 2008-06-30\n    2008-07-31 2008-08-29 2008-09-30 2008-10-31 2008-11-28\n    2008-12-31 2009-01-30 2009-02-27 2009-03-31 2009-04-30\n    2009-05-29 2009-06-30 2009-07-31 2009-08-31 2009-09-30\n    2009-10-30 2009-11-30 2009-12-31 2010-01-29 2010-02-26\n    2010-03-31 2010-04-30 2010-05-28 2010-06-30 2010-07-30\n    2010-08-31 2010-09-30 2010-10-29 2010-11-30 2010-12-31\n    2011-01-31 2011-02-28 2011-03-31 2011-04-29 2011-05-31\n    2011-06-30 2011-07-29 2011-08-31 2011-09-30 2011-10-31\n    2011-11-30 2011-12-30 2012-01-31 2012-02-29 2012-03-30\n    2012-04-30 2012-05-31 2012-06-29 2012-07-31 2012-08-31\n    2012-09-28 2012-10-31 2012-11-30 2012-12-31 2013-01-31\n    2013-02-28 2013-03-28 2013-04-30 2013-05-31 2013-06-28\n    2013-07-31 2013-08-30 2013-09-30 2013-10-31 2013-11-29\n    2013-12-31 2014-01-31 2014-02-28 2014-03-31 2014-04-30\n    2014-05-30 2014-06-30 2014-07-31 2014-08-29 2014-09-30\n    2014-10-31 2014-11-28 2014-12-31 2015-01-30 2015-02-27\n    2015-03-31 2015-04-30 2015-05-29 2015-06-30 2015-07-31\n    2015-08-31 2015-09-30 2015-10-30 2015-11-30 2015-12-31\n    2016-01-29 2016-02-29 2016-03-31 2016-04-29 2016-05-31\n    2016-06-30 2016-07-29 2016-08-31 2016-09-30 2016-10-31\n    2016-11-30 2016-12-30 2017-01-31 2017-02-28 2017-03-31\n    2017-04-28 2017-05-31 2017-06-30 2017-07-31 2017-08-31\n    2017-09-29 2017-10-31 2017-11-30 2017-12-29 2018-01-31\n    2018-02-28 2018-03-29 2018-04-30 2018-05-31 2018-06-29\n    2018-07-31 2018-08-31 2018-09-28 2018-10-31 2018-11-30\n    2018-12-31 2019-01-31 2019-02-28 2019-03-29 2019-04-30\n    2019-05-31 2019-06-28 2019-07-31 2019-08-30 2019-09-30\n    2019-10-31 2019-11-29 2019-12-31 2020-01-31 2020-02-28\n    2020-03-31 2020-04-30 2020-05-29 2020-06-30 2020-07-31\n    2020-08-31 2020-09-30 2020-10-30 2020-11-30 2020-12-31\n    2021-01-29 2021-02-26 2021-03-31 2021-04-30 2021-05-28\n    2021-06-30 2021-07-30 2021-08-31 2021-09-30 2021-10-29\n    2021-11-30 2021-12-31\"\n \n#-----------------------------------\n# read input date string\n#-----------------------------------\n \n# trimws() : Remove Leading\/Trailing Whitespace\n# fill = TRUE : If the rows have unequal length, \n#               blank fields are implicitly added. \nvdate &lt;- c(t(read.table(text=trimws(str_vdate), \n                        fill = TRUE)))\n \nvdate &lt;- vdate[vdate != \"\"]\n \n#===============================================\n# select the last date for each year\n#===============================================\nidx_last   &lt;- match(paste0(2001:2021,\"-12\"), \n                    substr(vdate,1,7))\nvdate_last &lt;- vdate[idx_last]\n \n# > vdate_last\n# [1]  \"2001-12-31\" \"2002-12-31\" \"2003-12-31\" \"2004-12-31\"\n# [5]  \"2005-12-30\" \"2006-12-29\" \"2007-12-31\" \"2008-12-31\"\n# [9]  \"2009-12-31\" \"2010-12-31\" \"2011-12-30\" \"2012-12-31\"\n# [13] \"2013-12-31\" \"2014-12-31\" \"2015-12-31\" \"2016-12-30\"\n# [17] \"2017-12-29\" \"2018-12-31\" \"2019-12-31\" \"2020-12-31\"\n# [21] \"2021-12-31\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Setting x-axis as the selected dates<\/h3>\n\n\n\n<p>This is what I wanted to do in this post.<\/p>\n\n\n\n<p>When plotting a figure for a time series, the x-axis needs to be labeled as selected dates with sufficient spacings not a plain index number such as 1, 2, 3.<\/p>\n\n\n\n<p>We can use two arguments (<strong>at<\/strong>&nbsp;and&nbsp;<strong>labels<\/strong>) of&nbsp;<strong>axis()<\/strong>&nbsp;function as selected index and the corresponding dates (<strong>idx_last<\/strong>&nbsp;and&nbsp;<strong>vdate_last<\/strong>).<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#===============================================\n# This is what I wanted to do \n# (x axis as selected date)\n#===============================================\n \n# sample date\nnt &lt;- length(vdate)\nx = periodic.series(start.period = 50, length = nt)\ny = x + 0.2*rnorm(nt) # add some noise\n \n \n# plot \nx11(width=7, height=8); par(mfrow = c(2,1))\n \nplot(y, type = \"l\", lty=1, lwd=3, xaxt=\"n\", \n     main=\"year-month x-axis\", xlab = \"date\", col = 4)\naxis(1, at = idx_last, labels = vdate_last)\n \nplot(y, type = \"l\", lty=1, lwd=3, xaxt=\"n\", \n     main=\"year x-axis\", xlab = \"date\", col = 2)\naxis(1, at = idx_last, labels = substr(vdate_last,1,4))<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><em>Visit <a href=\"https:\/\/shleeai.blogspot.com\/2022\/10\/r-code-setting-x-axis-as-selected-dates.html\">SHLee AI Financial Model<\/a> blog for additional insights on this topic.<\/em><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, &#8230; on x-axis.<\/p>\n","protected":false},"author":662,"featured_media":194444,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,342],"tags":[806,487,6591],"contributors-categories":[13728],"class_list":{"0":"post-211890","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-r-development","12":"tag-data-science","13":"tag-r","14":"tag-rstats","15":"contributors-categories-sh-fintech-modeling"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>R Code: Setting X-Axis As The Selected Dates | IBKR Quant<\/title>\n<meta name=\"description\" content=\"This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/211890\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R Code: Setting X-Axis As The Selected Dates\" \/>\n<meta property=\"og:description\" content=\"This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-12T16:31:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-12T15:09:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sang-Heon Lee\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sang-Heon Lee\" \/>\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\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Sang-Heon Lee\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/0a959ff9de7f0465a07baa1fe1ae0200\"\n\t            },\n\t            \"headline\": \"R Code: Setting X-Axis As The Selected Dates\",\n\t            \"datePublished\": \"2024-09-12T16:31:12+00:00\",\n\t            \"dateModified\": \"2025-02-12T15:09:15+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/\"\n\t            },\n\t            \"wordCount\": 255,\n\t            \"commentCount\": 0,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/08\\\/R-programming-user-pressing-button.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"R\",\n\t                \"rstats\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/\",\n\t            \"name\": \"R Code: Setting X-Axis As The Selected Dates | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/08\\\/R-programming-user-pressing-button.jpg\",\n\t            \"datePublished\": \"2024-09-12T16:31:12+00:00\",\n\t            \"dateModified\": \"2025-02-12T15:09:15+00:00\",\n\t            \"description\": \"This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-setting-x-axis-as-the-selected-dates\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/08\\\/R-programming-user-pressing-button.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/08\\\/R-programming-user-pressing-button.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Quant\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/0a959ff9de7f0465a07baa1fe1ae0200\",\n\t            \"name\": \"Sang-Heon Lee\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/sang-heonlee\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"R Code: Setting X-Axis As The Selected Dates | IBKR Quant","description":"This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.","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:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/211890\/","og_locale":"en_US","og_type":"article","og_title":"R Code: Setting X-Axis As The Selected Dates","og_description":"This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/","og_site_name":"IBKR Campus US","article_published_time":"2024-09-12T16:31:12+00:00","article_modified_time":"2025-02-12T15:09:15+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg","type":"image\/jpeg"}],"author":"Sang-Heon Lee","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sang-Heon Lee","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/"},"author":{"name":"Sang-Heon Lee","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/0a959ff9de7f0465a07baa1fe1ae0200"},"headline":"R Code: Setting X-Axis As The Selected Dates","datePublished":"2024-09-12T16:31:12+00:00","dateModified":"2025-02-12T15:09:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/"},"wordCount":255,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg","keywords":["Data Science","R","rstats"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","R Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/","name":"R Code: Setting X-Axis As The Selected Dates | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg","datePublished":"2024-09-12T16:31:12+00:00","dateModified":"2025-02-12T15:09:15+00:00","description":"This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-setting-x-axis-as-the-selected-dates\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg","width":1000,"height":563,"caption":"Quant"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/0a959ff9de7f0465a07baa1fe1ae0200","name":"Sang-Heon Lee","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/sang-heonlee\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/08\/R-programming-user-pressing-button.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/211890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/662"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=211890"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/211890\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/194444"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=211890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=211890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=211890"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=211890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}