Set the background color for quantmod::chart_Series












2















I have an xts object named adjPrices.xts that contains an OHLC stock price history. The function quantmod::chartSeries, when called as follows, plots this data in a chart with a black background:



chartSeries(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)


enter image description here



However, quantmod::chart_Series with the same options creates a chart with a white background:



chart_Series(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)


enter image description here



I want to change the background color of this second plot to black, and I am following the approach suggested in this answer. The color attributes of chart_theme() are



> chart_theme()$col
$`bg`
[1] "#FFFFFF"

$label.bg
[1] "#F0F0F0"

$grid
[1] "#F0F0F0"

$grid2
[1] "#F5F5F5"

$ticks
[1] "#999999"

$labels
[1] "#333333"

$line.col
[1] "darkorange"

$dn.col
[1] "red"

$up.col
[1] NA

$dn.border
[1] "#333333"

$up.border
[1] "#333333"


This suggests to me that I can set the background color to black as follows:



myTheme <- chart_theme()
myTheme$col$`bg` <- "black"
chart_Series(adjPrices.xts,
subset = '2014-07-01::2015-07-01',
theme = myTheme,
type = 'bars',
name = paste(symbol, 'Adjusted Prices'),
TA = NULL)


But the resulting chart still has a white background:
enter image description here
I also tried defining myTheme as follows:



myTheme <- chart_theme()
myTheme$col$`bg` <- "#000000"


but the resulting chart still has a white background.



How can I set a black background when using chart_Series()?










share|improve this question



























    2















    I have an xts object named adjPrices.xts that contains an OHLC stock price history. The function quantmod::chartSeries, when called as follows, plots this data in a chart with a black background:



    chartSeries(adjPrices.xts,
    subset = '2014-07-01::2015-07-01',
    type = 'bars',
    name = paste(symbol, 'Adjusted Prices'),
    TA = NULL)


    enter image description here



    However, quantmod::chart_Series with the same options creates a chart with a white background:



    chart_Series(adjPrices.xts,
    subset = '2014-07-01::2015-07-01',
    type = 'bars',
    name = paste(symbol, 'Adjusted Prices'),
    TA = NULL)


    enter image description here



    I want to change the background color of this second plot to black, and I am following the approach suggested in this answer. The color attributes of chart_theme() are



    > chart_theme()$col
    $`bg`
    [1] "#FFFFFF"

    $label.bg
    [1] "#F0F0F0"

    $grid
    [1] "#F0F0F0"

    $grid2
    [1] "#F5F5F5"

    $ticks
    [1] "#999999"

    $labels
    [1] "#333333"

    $line.col
    [1] "darkorange"

    $dn.col
    [1] "red"

    $up.col
    [1] NA

    $dn.border
    [1] "#333333"

    $up.border
    [1] "#333333"


    This suggests to me that I can set the background color to black as follows:



    myTheme <- chart_theme()
    myTheme$col$`bg` <- "black"
    chart_Series(adjPrices.xts,
    subset = '2014-07-01::2015-07-01',
    theme = myTheme,
    type = 'bars',
    name = paste(symbol, 'Adjusted Prices'),
    TA = NULL)


    But the resulting chart still has a white background:
    enter image description here
    I also tried defining myTheme as follows:



    myTheme <- chart_theme()
    myTheme$col$`bg` <- "#000000"


    but the resulting chart still has a white background.



    How can I set a black background when using chart_Series()?










    share|improve this question

























      2












      2








      2








      I have an xts object named adjPrices.xts that contains an OHLC stock price history. The function quantmod::chartSeries, when called as follows, plots this data in a chart with a black background:



      chartSeries(adjPrices.xts,
      subset = '2014-07-01::2015-07-01',
      type = 'bars',
      name = paste(symbol, 'Adjusted Prices'),
      TA = NULL)


      enter image description here



      However, quantmod::chart_Series with the same options creates a chart with a white background:



      chart_Series(adjPrices.xts,
      subset = '2014-07-01::2015-07-01',
      type = 'bars',
      name = paste(symbol, 'Adjusted Prices'),
      TA = NULL)


      enter image description here



      I want to change the background color of this second plot to black, and I am following the approach suggested in this answer. The color attributes of chart_theme() are



      > chart_theme()$col
      $`bg`
      [1] "#FFFFFF"

      $label.bg
      [1] "#F0F0F0"

      $grid
      [1] "#F0F0F0"

      $grid2
      [1] "#F5F5F5"

      $ticks
      [1] "#999999"

      $labels
      [1] "#333333"

      $line.col
      [1] "darkorange"

      $dn.col
      [1] "red"

      $up.col
      [1] NA

      $dn.border
      [1] "#333333"

      $up.border
      [1] "#333333"


      This suggests to me that I can set the background color to black as follows:



      myTheme <- chart_theme()
      myTheme$col$`bg` <- "black"
      chart_Series(adjPrices.xts,
      subset = '2014-07-01::2015-07-01',
      theme = myTheme,
      type = 'bars',
      name = paste(symbol, 'Adjusted Prices'),
      TA = NULL)


      But the resulting chart still has a white background:
      enter image description here
      I also tried defining myTheme as follows:



      myTheme <- chart_theme()
      myTheme$col$`bg` <- "#000000"


      but the resulting chart still has a white background.



      How can I set a black background when using chart_Series()?










      share|improve this question














      I have an xts object named adjPrices.xts that contains an OHLC stock price history. The function quantmod::chartSeries, when called as follows, plots this data in a chart with a black background:



      chartSeries(adjPrices.xts,
      subset = '2014-07-01::2015-07-01',
      type = 'bars',
      name = paste(symbol, 'Adjusted Prices'),
      TA = NULL)


      enter image description here



      However, quantmod::chart_Series with the same options creates a chart with a white background:



      chart_Series(adjPrices.xts,
      subset = '2014-07-01::2015-07-01',
      type = 'bars',
      name = paste(symbol, 'Adjusted Prices'),
      TA = NULL)


      enter image description here



      I want to change the background color of this second plot to black, and I am following the approach suggested in this answer. The color attributes of chart_theme() are



      > chart_theme()$col
      $`bg`
      [1] "#FFFFFF"

      $label.bg
      [1] "#F0F0F0"

      $grid
      [1] "#F0F0F0"

      $grid2
      [1] "#F5F5F5"

      $ticks
      [1] "#999999"

      $labels
      [1] "#333333"

      $line.col
      [1] "darkorange"

      $dn.col
      [1] "red"

      $up.col
      [1] NA

      $dn.border
      [1] "#333333"

      $up.border
      [1] "#333333"


      This suggests to me that I can set the background color to black as follows:



      myTheme <- chart_theme()
      myTheme$col$`bg` <- "black"
      chart_Series(adjPrices.xts,
      subset = '2014-07-01::2015-07-01',
      theme = myTheme,
      type = 'bars',
      name = paste(symbol, 'Adjusted Prices'),
      TA = NULL)


      But the resulting chart still has a white background:
      enter image description here
      I also tried defining myTheme as follows:



      myTheme <- chart_theme()
      myTheme$col$`bg` <- "#000000"


      but the resulting chart still has a white background.



      How can I set a black background when using chart_Series()?







      r quantmod






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 19:45









      RobertRobert

      691920




      691920
























          1 Answer
          1






          active

          oldest

          votes


















          1














          At the moment you can't. There is an old not yet resolved issue #25 for this on github. A workaround would be calling on the R graphical parameters with par:



          This will create a black background.



          par_old <- par(bg = "black")
          chart_Series(SPY)
          par(par_old)


          Some other workarounds are using rtsplot. Based on R base graphics and has on option to draw candle charts. Background colours are set via par:



          rtsplot::rtsplot(SPY, type = "candle")


          xts has a plotting environment plot.xts, but that one doesn't handle candle bars.



          Tidyquant has geom_candlestick for ggplot2, but these fail at the moment if you use ggplot2 > 3.0. See this tidyquant github issue






          share|improve this answer























            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%2f53461776%2fset-the-background-color-for-quantmodchart-series%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









            1














            At the moment you can't. There is an old not yet resolved issue #25 for this on github. A workaround would be calling on the R graphical parameters with par:



            This will create a black background.



            par_old <- par(bg = "black")
            chart_Series(SPY)
            par(par_old)


            Some other workarounds are using rtsplot. Based on R base graphics and has on option to draw candle charts. Background colours are set via par:



            rtsplot::rtsplot(SPY, type = "candle")


            xts has a plotting environment plot.xts, but that one doesn't handle candle bars.



            Tidyquant has geom_candlestick for ggplot2, but these fail at the moment if you use ggplot2 > 3.0. See this tidyquant github issue






            share|improve this answer




























              1














              At the moment you can't. There is an old not yet resolved issue #25 for this on github. A workaround would be calling on the R graphical parameters with par:



              This will create a black background.



              par_old <- par(bg = "black")
              chart_Series(SPY)
              par(par_old)


              Some other workarounds are using rtsplot. Based on R base graphics and has on option to draw candle charts. Background colours are set via par:



              rtsplot::rtsplot(SPY, type = "candle")


              xts has a plotting environment plot.xts, but that one doesn't handle candle bars.



              Tidyquant has geom_candlestick for ggplot2, but these fail at the moment if you use ggplot2 > 3.0. See this tidyquant github issue






              share|improve this answer


























                1












                1








                1







                At the moment you can't. There is an old not yet resolved issue #25 for this on github. A workaround would be calling on the R graphical parameters with par:



                This will create a black background.



                par_old <- par(bg = "black")
                chart_Series(SPY)
                par(par_old)


                Some other workarounds are using rtsplot. Based on R base graphics and has on option to draw candle charts. Background colours are set via par:



                rtsplot::rtsplot(SPY, type = "candle")


                xts has a plotting environment plot.xts, but that one doesn't handle candle bars.



                Tidyquant has geom_candlestick for ggplot2, but these fail at the moment if you use ggplot2 > 3.0. See this tidyquant github issue






                share|improve this answer













                At the moment you can't. There is an old not yet resolved issue #25 for this on github. A workaround would be calling on the R graphical parameters with par:



                This will create a black background.



                par_old <- par(bg = "black")
                chart_Series(SPY)
                par(par_old)


                Some other workarounds are using rtsplot. Based on R base graphics and has on option to draw candle charts. Background colours are set via par:



                rtsplot::rtsplot(SPY, type = "candle")


                xts has a plotting environment plot.xts, but that one doesn't handle candle bars.



                Tidyquant has geom_candlestick for ggplot2, but these fail at the moment if you use ggplot2 > 3.0. See this tidyquant github issue







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 25 '18 at 12:22









                phiverphiver

                13k92634




                13k92634






























                    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%2f53461776%2fset-the-background-color-for-quantmodchart-series%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

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)