Announcement

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

  • Alternative to stacked bar graph

    Hi All,

    I'm looking for an alternative to the maligned stacked bar graph.

    The graph below shows the relationship of x1 with y and x2 with y and additionally markers are connected by a line to highlight the relationship between x1 and x2.

    I would like to vary the colour and shape of the markers so that x1 appears as a red triangle and x2 remains with the default settings, while keeping the line connecting the two.

    How may I do this?

    Thankyou!

    Janine

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(x1 x2 y)
    0 0  2
    1 0  3
    2 0  5
    3 0  1
    4 0  .
    5 0  4
    0 1 18
    1 1  2
    2 1  .
    3 1  8
    4 1  2
    5 1  .
    end
    label values x2 x2label
    label def x2label 0 "A", modify
    label def x2label 1 "B", modify


    scatter y x2 , by(x1 , note("") title("alternative to stacked bar chart") col(6) ) c(l) lpattern(dash) ///
    xscale(r(0 1)) xlab(0 "A" 1 "B") ylab(0(5)20) ///
    ytitle("y") xtitle("x2")


  • #2
    Not sure if the following is what you are asking for.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(x1 x2 y)
    0 0  2
    1 0  3
    2 0  5
    3 0  1
    4 0  .
    5 0  4
    0 1 18
    1 1  2
    2 1  .
    3 1  8
    4 1  2
    5 1  .
    end
    label values x2 x2label
    label def x2label 0 "A", modify
    label def x2label 1 "B", modify
    
    tw scatter y x2 , msy(none) by(x1 , note("") leg(off) ///
    title("alternative to stacked bar chart") col(6) ) c(l) lc(black) ///
    lpattern(dash) xscale(r(0 1)) xlab(0 "A" 1 "B") ylab(0(5)20) ///
    ytitle("y") xtitle("x2") || scatter y x2 if !x2, msy(t) mcolor(red) ///
     || scatter y x2 if x2, mc(blue)

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	37.3 KB
ID:	1756571

    Comment


    • #3
      Oh I see! I didn't think of that solution.

      Thankyou Musau,

      Janine

      Comment


      • #4
        As usual, there are many ways to plot such data, and which works best depends on the data, who is reading it, local fashions or customs in any sub-field. and so on.

        Some possibilities were discussed in https://journals.sagepub.com/doi/epd...867X0900900408

        Comment

        Working...
        X