{"id":241834,"date":"2026-04-22T12:06:35","date_gmt":"2026-04-22T16:06:35","guid":{"rendered":"https:\/\/ibkrcampus.com\/campus\/?p=241834"},"modified":"2026-04-22T12:08:41","modified_gmt":"2026-04-22T16:08:41","slug":"how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/","title":{"rendered":"How to Draw a Candlestick Chart in R? &#8211; Both ggplot2 and plotly"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>The article &#8220;How to Draw a Candlestick Chart in R? &#8211; Both ggplot2 and plotly&#8221; was originally published on <a href=\"https:\/\/ozancanozdemir.github.io\/r\/candlestick-using-ggplot2-plotly-in-R\/\">Ozancan Ozdemir Blog<\/a>.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Candlestick charts are a type of financial chart used to depict the price movements of an asset over a specific period. Each \u201ccandlestick\u201d represents a time frame\u2014such as a day, hour, or minute\u2014and displays four key pieces of data: the opening price, closing price, highest price, and lowest price within that period. The body of the candlestick shows the range between the opening and closing prices, while the wicks (also known as shadows) extend to the highest and lowest prices. If the closing price is higher than the opening price, the candlestick is typically colored green or left hollow to indicate a price increase. Conversely, if the closing price is lower than the opening price, it is colored red or filled to signify a price decrease.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here you can see a disclosure for the figures in the candlestick chart.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"356\" height=\"305\" data-src=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/Candlestick-Chart-in-R-Ozancan.png\" alt=\"How to Draw a Candlestick Chart in R\" class=\"wp-image-241836 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/Candlestick-Chart-in-R-Ozancan.png 356w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/Candlestick-Chart-in-R-Ozancan-300x257.png 300w\" data-sizes=\"(max-width: 356px) 100vw, 356px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 356px; aspect-ratio: 356\/305;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Candlestick charts are valuable tools for traders and analysts because they provide a visual representation of market sentiment and price action. By analyzing patterns and formations\u2014such as dojis, hammers, and engulfing patterns\u2014traders can gain insights into potential trend reversals or continuations. These patterns help in making informed decisions about when to enter or exit trades. Understanding how to read and interpret candlestick charts is essential for anyone looking to navigate the financial markets effectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately. The ggplot2 library is a popular data visualization package that allows you to create a wide range of plots, while the plotly library enables you to create interactive charts that can be easily shared and explored.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thus, we need to employ four packages first. tidyquant, quantmod, ggplot2, and plotly. The quantmod package is used to retrieve financial data from Yahoo Finance, while the plotly package is used to create static and interactive candlestick charts, respectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">tidyquant package has a built-in function used to create a candlestick chart as a ggplot object, geom_candlestick.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Constructing a candlestick chart with ggplot2<\/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=\"\">## call libraries\nlibrary(ggplot2)\nlibrary(tidyquant)\nlibrary(quantmod)\nlibrary(plotly)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After calling the libraries, we can retrieve the historical stock prices of a company from Yahoo Finance using the getSymbols() function from the quantmod package. In this example, we will retrieve the historical stock prices of Apple Inc. (AAPL) and store them in a data frame.<\/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=\"\">## retrieve historical stock prices\ngetSymbols(\"AAPL\", src = \"yahoo\")\n\nAAPL<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we will create a data frame from the stock prices and select the last 30 observations to create a candlestick chart. The geom_candlestick() function from the tidyquant package is used to create the candlestick chart.<\/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=\"\">df &lt;- data.frame(Date=index(AAPL),coredata(AAPL)) |&gt; tail (30)\nhead(df)<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> Date AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume\n4478 2024-10-16    231.60    232.12   229.84     231.78    34082200\n4479 2024-10-17    233.43    233.85   230.52     232.15    32993800\n4480 2024-10-18    236.18    236.18   234.01     235.00    46431500\n4481 2024-10-21    234.45    236.85   234.45     236.48    36254500\n4482 2024-10-22    233.89    236.22   232.60     235.86    38846600\n4483 2024-10-23    234.08    235.14   227.76     230.76    52287000\n     AAPL.Adjusted\n4478      231.5253\n4479      231.8949\n4480      234.7417\n4481      236.2201\n4482      235.6008\n4483      230.5064<\/pre>\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=\"\">## create a candlestick chart\ndf |&gt; ggplot(aes(x = Date, y = AAPL.Close)) +\n    geom_candlestick(aes(open = AAPL.Open, high = AAPL.High, low = AAPL.Low, close = AAPL.Close))+ \n    coord_x_date(xlim = c(min(df$Date), max(df$Date)), \n                 ylim = c(min(df$AAPL.Low)-10, max(df$AAPL.Close)+20))<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"786\" data-src=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-2-1100x786.png\" alt=\"How to Draw a Candlestick Chart in R\" class=\"wp-image-241851 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-2-1100x786.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-2-700x500.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-2-300x214.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-2-768x549.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-2.png 1344w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/786;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Source: Yahoo<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This R code generates a candlestick chart of Apple\u2019s stock prices using the ggplot2 library, enhanced with a function like geom_candlestick() from the tidyquant package. It starts by piping the data frame df into ggplot(), mapping the x-axis to Date and the y-axis to AAPL.Close. The geom_candlestick() layer is added to visualize the open, high, low, and close prices of the stock over time, using the respective columns in df. Finally, coord_x_date() adjusts the x-axis to cover the full date range of the data and sets the y-axis limits slightly beyond the minimum and maximum stock prices (subtracting 10 from the lowest low and adding 20 to the highest close) to provide padding for better visualization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, the produced chart is slightly different than the usual one because of the default color settings. We can change the color settings by adding the following arguments to the geom_candlestick() function:<\/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=\"\">## create a candlestick chart\ndf |&gt; ggplot(aes(x = Date, y = AAPL.Close)) +\n    geom_candlestick(aes(open = AAPL.Open, high = AAPL.High, low = AAPL.Low, close = AAPL.Close),colour_up = \"darkgreen\",fill_up = \"darkgreen\")+ \n    coord_x_date(xlim = c(min(df$Date), max(df$Date)), \n                 ylim = c(min(df$AAPL.Low)-10, max(df$AAPL.Close)+20))<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"786\" data-src=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-3-1100x786.png\" alt=\"How to Draw a Candlestick Chart in R\" class=\"wp-image-241854 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-3-1100x786.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-3-700x500.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-3-300x214.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-3-768x549.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-3.png 1344w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/786;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Source: Yahoo<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since it is a ggplot object, you can manipulate this chart by editing its theme, adding titles or labels, or changing the color scheme. You can also save the chart as an image file or embed it in an R Markdown document or Shiny application.<\/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=\"\">## create a candlestick chart\ndf |&gt; ggplot(aes(x = Date, y = AAPL.Close)) +\n    geom_candlestick(aes(open = AAPL.Open, high = AAPL.High, low = AAPL.Low, close = AAPL.Close),colour_up = \"darkgreen\",fill_up = \"darkgreen\")+ \n    coord_x_date(xlim = c(min(df$Date), max(df$Date)), \n                 ylim = c(min(df$AAPL.Low)-10, max(df$AAPL.Close)+20)) + \n  labs(title =paste(\"Apple Inc. (AAPL) Stock Prices Between\",min(df$Date),\"and\",max(df$Date)) , x = \"Date\", y = \"Price\")<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"786\" data-src=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-4-1100x786.png\" alt=\"How to Draw a Candlestick Chart in R\" class=\"wp-image-241856 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-4-1100x786.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-4-700x500.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-4-300x214.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-4-768x549.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-4.png 1344w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/786;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Source: Yahoo<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Constructing a candlestick chart with plotly<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As stated below, plotly is a powerful library that allows you to create interactive charts in R. In this example, we will use the plot_ly() function to create an interactive candlestick chart of Apple\u2019s stock prices. The plot_ly() function takes the data frame df as input and specifies the x-axis as Date and the y-axis as the open, close, high, and low prices of the stock. The type argument is set to \u201ccandlestick\u201d to create a candlestick chart, and the layout() function is used to add a title to the chart.<\/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=\"\">fig &lt;- df %&gt;% plot_ly(x = ~Date, type=\"candlestick\",\n          open = ~AAPL.Open, close = ~AAPL.Close,\n          high = ~AAPL.High, low = ~AAPL.Low) \nfig &lt;- fig %&gt;% layout(title = paste(\"Apple Inc. (AAPL) Stock Prices Between\",min(df$Date),\"and\",max(df$Date)))\n\nfig<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"799\" height=\"464\" data-src=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-5.png\" alt=\"How to Draw a Candlestick Chart in R\" class=\"wp-image-241858 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-5.png 799w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-5-700x407.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-5-300x174.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2026\/04\/candlestick-chart-ozancan-5-768x446.png 768w\" data-sizes=\"(max-width: 799px) 100vw, 799px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 799px; aspect-ratio: 799\/464;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Source: Yahoo<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This R code generates an interactive candlestick chart of Apple\u2019s stock prices using the plotly library. It starts by piping the data frame df into the plot_ly() function, specifying the x-axis as Date and the y-axis as the open, close, high, and low prices of the stock. The type argument is set to \u201ccandlestick\u201d to create a candlestick chart, and the layout() function is used to add a title to the chart. The resulting chart is interactive, allowing you to zoom in, pan, and hover over data points to view additional information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can visit the\u00a0<a href=\"https:\/\/plotly.com\/r\/candlestick-charts\/\">official documentation<\/a>\u00a0of the plotly library to learn more about creating interactive candlestick charts and customizing their appearance and behavior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.<\/p>\n","protected":false},"author":1730,"featured_media":181803,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":true,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[339,343,338,341,342],"tags":[21404,7560,2533,21405,21403,1410,1408,985,1044],"contributors-categories":[21066],"class_list":["post-241834","post","type-post","status-publish","format-standard","has-post-thumbnail","category-data-science","category-programing-languages","category-ibkr-quant-news","category-quant-development","category-r-development","tag-candlestick-chart","tag-data-visualization","tag-ggplot2","tag-interactive-charts","tag-library","tag-plotly","tag-quantmod","tag-r-programming","tag-tidyquant","contributors-categories-ozancan-ozdemir"],"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.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Draw a Candlestick Chart in R? &#8211; Both ggplot2 and plotly<\/title>\n<meta name=\"description\" content=\"In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.\" \/>\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\/241834\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Draw a Candlestick Chart in R? \u2013 Both ggplot2 and plotly\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-22T16:06:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-22T16:08:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ozancan Ozdemir\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ozancan Ozdemir\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 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:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Ozancan Ozdemir\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/0952e43caa69579bed51ba54d811f3e7\"\n\t            },\n\t            \"headline\": \"How to Draw a Candlestick Chart in R? &#8211; Both ggplot2 and plotly\",\n\t            \"datePublished\": \"2026-04-22T16:06:35+00:00\",\n\t            \"dateModified\": \"2026-04-22T16:08:41+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/\"\n\t            },\n\t            \"wordCount\": 880,\n\t            \"commentCount\": 0,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/R-programing.jpg\",\n\t            \"keywords\": [\n\t                \"candlestick chart\",\n\t                \"Data Visualization\",\n\t                \"ggplot2\",\n\t                \"interactive charts\",\n\t                \"library\",\n\t                \"plotly\",\n\t                \"quantmod\",\n\t                \"R Programming\",\n\t                \"tidyquant\"\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:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/\",\n\t            \"name\": \"How to Draw a Candlestick Chart in R? - Both ggplot2 and plotly | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/R-programing.jpg\",\n\t            \"datePublished\": \"2026-04-22T16:06:35+00:00\",\n\t            \"dateModified\": \"2026-04-22T16:08:41+00:00\",\n\t            \"description\": \"In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/R-programing.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/02\\\/R-programing.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\n\t            \"caption\": \"Sign Constrained Lasso with R code\"\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\\\/0952e43caa69579bed51ba54d811f3e7\",\n\t            \"name\": \"Ozancan Ozdemir\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/ozancan1ozdemir\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Draw a Candlestick Chart in R? &#8211; Both ggplot2 and plotly","description":"In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.","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\/241834\/","og_locale":"en_US","og_type":"article","og_title":"How to Draw a Candlestick Chart in R? \u2013 Both ggplot2 and plotly","og_description":"In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/","og_site_name":"IBKR Campus US","article_published_time":"2026-04-22T16:06:35+00:00","article_modified_time":"2026-04-22T16:08:41+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg","type":"image\/jpeg"}],"author":"Ozancan Ozdemir","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ozancan Ozdemir","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/#article","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/"},"author":{"name":"Ozancan Ozdemir","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/0952e43caa69579bed51ba54d811f3e7"},"headline":"How to Draw a Candlestick Chart in R? &#8211; Both ggplot2 and plotly","datePublished":"2026-04-22T16:06:35+00:00","dateModified":"2026-04-22T16:08:41+00:00","mainEntityOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/"},"wordCount":880,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg","keywords":["candlestick chart","Data Visualization","ggplot2","interactive charts","library","plotly","quantmod","R Programming","tidyquant"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","R Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/","url":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/","name":"How to Draw a Candlestick Chart in R? - Both ggplot2 and plotly | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/#primaryimage"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg","datePublished":"2026-04-22T16:06:35+00:00","dateModified":"2026-04-22T16:08:41+00:00","description":"In this tutorial, I aim to illustrate how you can construct a candlestick chart in R by using ggplot2 and plotly libraries, separately.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-draw-a-candlestick-chart-in-r-both-ggplot2-and-plotly\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg","width":900,"height":550,"caption":"Sign Constrained Lasso with R code"},{"@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\/0952e43caa69579bed51ba54d811f3e7","name":"Ozancan Ozdemir","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/ozancan1ozdemir\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/02\/R-programing.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/241834","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\/1730"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=241834"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/241834\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/181803"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=241834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=241834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=241834"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=241834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}