Announcement

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

  • Categorical Bar Chart (Binary Variables) with Multiple Variables

    Hi Users,

    Another graphing question. I have a list of 8 adoption barriers in which survey respondents either said "yes" or "no" corresponding to whether certain barriers would deter them drop adopting technology. See the data below.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str55 barrier byte(Yes No)
    "Lack of Awareness"                                       70 30
    "I do not see a Need for Blockchains on my Farm"          35 65
    "Uncertain Whether Blockchains Meet my Marketing Needs"   67 33
    "Unsure Whether Blockchains will Meet my Customers Needs" 60 40
    "Uncertain Whether Blockchains will Improve Food Safety"  45 55
    "Data Sharing Concerns"                                   52 48
    "Traceback Concerns"                                      22 78
    "Lack of Adoption"                                        52 48
    end
    *note: Yes and No refer to percentages (As you'll see they each add up to 100 - I just converted these into integers as opposed to percentages)

    I want a graph to have both the yes and no but I don't want them stacked. I have used the following code to graph just the "Yes":

    Code:
    graph hbar Yes, over(barrier, sort(1)) bar(1, color(none)) scheme(s1color) title("Blockchain Adoption Barriers", size(medium)) ytitle("Freq.") blabel(total) ylabel(0(10)100) xsize(7)
    I would like something like the following (I did this on excel)
    Click image for larger version

Name:	Picture1.png
Views:	1
Size:	23.1 KB
ID:	1492641


    P.S. It doesn't matter whether the bars are horizontal or vertical. Thanks in advance!

  • #2
    You need to shorten your descriptions of the categories, but something like this should do

    Code:
    graph hbar Yes No, over(barrier) scheme(s2mono) legend(order(1 "Yes" 2 "No"))
    See

    Code:
    help graph bar
    for more options and examples.

    Comment


    • #3
      I want a graph to have both the yes and no but I don't want them stacked.
      If you need the graphs side by side, it may be difficult to manage the labels using graph hbar. Here is an alternative using tabplot from Stata Journal, authored by Nick Cox.

      Code:
      *RESHAPE DATA AND LABEL CATEGORIES
      rename (Yes No) (response#), addnumber(1)
      reshape long response, i(barrier)
      label define j 1 "Yes" 2 "No"
      label values _j j
      
      *PLOT
      *findit tabplot to install
      tabplot barrier [iw=response], by(_j, compact note("") ///
      title("Blockchain Adoption Barriers", place(e))) hor yla(, labsize(small)) /// 
      scheme(s2mono) showval(mlabsize(vsmall)) ytitle("")
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.8 KB
ID:	1492655

      Comment


      • #4
        Thanks!!!! This was very helpful!

        Comment

        Working...
        X