Announcement

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

  • Overlaying/combining bar and line graphs with two bar categories

    Hello everyone,

    I'm trying to create a combined line and bar graph with two categories for my bar chart. I have monthly data for the line chart, but only annual data for the bar charts (I filled all months of the respective year with the same value). Hence, I typed:

    Code:
    graph twoway (bar inflow outflow time) (line leiharb time, lc(black)) if jahr>=1998
    The result is:
    time_series_workers_dynamics1.png


    As you can see, the first problem is that the second category (here: outflow) completely covers the first category (here: inflow). Thus, I have tried to circumvent this problem by replacing the first six months of "inflow" and the last six month of "outflow" with missing:

    Code:
    * MANIPULATE VARIABLE FOR GRAPH
    replace inflow = . if monat>=7
    replace outflow = . if monat<=6
    
    * GRAPH
    graph twoway (bar inflow outflow time) (line leiharb time, lc(black)) if jahr>=1998
    Now, the result is:

    time_series_workers_dynamics2.png

    Although, it looks better now, the problem is that there are small with lines between the bar since one blue/red bar is actually comprised of 6 smaller (identical but separate) bars. I tried to simply disable the lines of the smaller bars by experimenting with the "lintensity(0)" option. However, Stata is telling me that this option is not allowed (probably because I am combining two graphs). Thus, this command does not work:

    Code:
    graph twoway (bar inflow outflow time, lintensity(0)) (line leiharb time, lc(black)) if jahr>=1998
    option lintensity() not allowed
    Does anyone have an idea how I can create such a combined graph which does not suffer from the shortcomings of my current graph.

    Thank you in advance!

    Best regards,
    Sebastian

  • #2
    When I enlarge the second figure, what I see is that the fill color and line color of the bars are not the same. You can try something like this:

    graph twoway (bar inflow time, lcolor(blue) fcolor(blue)) (bar outflow time, lcolor(red) fcolor(red)) ......


    help barlook_options
    help colorstyle

    Comment


    • #3
      Thank you Cyrus for your answer. I tried your code:

      Code:
      graph twoway (bar inflow time, fcolor(blue) lcolor(blue)) (bar outflow time, lcolor(red) fcolor(red)) (line leiharb time, lc(black)) if jahr>=1998
      The result is this:
      time_series_workers_dynamics3.png

      Even though, the border between the small bars becomes less apparent, it looks like that there is still a different color between the bars (to me it looks a little darker).

      After experimenting with various options, I finally found a way to solve the problem. If someone is interested in the solution: One needs to tell Stata that the fill intensity should be 100. After doing that the bars (including their borders) have the same color.

      Code:
      graph twoway (bar inflow time, fintensity(inten100) ) (bar outflow time, fintensity(inten100) ) (line leiharb time, lc(black)) if jahr>=1998
      Cyrus, thank you again for inspiring me to experiment with the "look of bar" options a little more.

      Comment


      • #4
        a

        Comment

        Working...
        X