Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Commands to colour the bars in a bar chart individually

    I use
    Code:
    graph bar, over(myVar)
    to create a bar chart. The bars have all the same color except when I select in the graph editor the bar region option "Cycle through over categories...", but even then the colors are just set somehow - and I get a legend (I do not want) instead of labels on the axis.

    I would like to specify a scheme of maybe 3-4 colors the bars cycle through. Any way to do this via options to the graph bar command or similar? That is more reproducible than via the graph edtor.

    Many thanks,
    Walter


  • #2
    Hello Walter,

    Welcome to the Stata Forum!

    You may wish to take a look at the "lookofbar_options".

    From the help files:

    bar(#, barlook_options) specifies the look of the yvar bars. bar(1, ...) refers to the bar associated with the first yvar, bar(2, ...) refers to the bar associated with the second,
    and so on. The most useful barlook_option is color(colorstyle), which sets the color of the bar. For instance, you might specify bar(1, color(green)) to make the bar associated
    with the first yvar green. See [G-4] colorstyle for a list of color choices, and see [G-3] barlook_options for information on the other barlook_options.
    Hopefully that helps.

    Best,

    Marcos
    Best regards,

    Marcos

    Comment


    • #3
      Not to forget, may you just want a set of non-specified colors to "cycle through", you may add -asyvars- in the options.
      Best regards,

      Marcos

      Comment


      • #4
        On over-use of colours, see Naomi Robbins as quoted at https://twitter.com/xangregg/status/700745391164100608

        An alternative to a colouring book is no colours at all. Let the word labels be informative. That's their job.

        Code:
        sysuse auto, clear
        graph hbar (asis) mpg if foreign, over(make, sort(1)) bar(1, bfcolor(none)) scheme(s1color)
        Click image for larger version

Name:	cars.png
Views:	1
Size:	17.0 KB
ID:	1359942

        A dot chart would be even better....

        Last edited by Nick Cox; 11 Oct 2016, 17:14.

        Comment


        • #5
          Originally posted by Marcos Almeida View Post
          Not to forget, may you just want a set of non-specified colors to "cycle through", you may add -asyvars- in the options.
          Thanks Marcos. Colour-wise that's exactly what I want! My graph via
          Code:
          graph bar, over(q166a_ORC_graph) asyvars legend(off)
          bow looks like:
          Click image for larger version

Name:	Graph_no_labels.png
Views:	2
Size:	25.9 KB
ID:	1359947

          However I cannot get the bars labeled like it is done without asyvars:
          Click image for larger version

Name:	Graph_with_labels_but_no_cycle_col.png
Views:	2
Size:	81.2 KB
ID:	1359948

          I do not want the legend which gets auto-generated with asyvars. How can I tell Stata to generate labels when using asyvars?

          Many thanks for any pointers,
          Walter

          Attached Files

          Comment


          • #6
            I encountered same questions. Although all have been past long ago, we can bring these threads together. The best solution is refered here:
            Originally posted by Nick Cox View Post
            Just one trick separates you from what you want:

            http://www.stata-journal.com/sjpdf.h...iclenum=gr0049
            and another similar post here: https://www.statalist.org/forums/for...play-bar-label

            Comment

            Working...
            X