Announcement

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

  • can we change the look of histogram to slash background?

    can we change the look of histogram to slash background, like the below?
    Click image for larger version

Name:	1.png
Views:	1
Size:	283.7 KB
ID:	1650136

  • #2
    Not easily. A thread in 2007 mostly still applies. https://www.stata.com/statalist/arch.../msg00188.html

    Sergiy Radyakin some years ago did write some code to subvert this lack. I have lost track of what it is (or was) called and whether (how) it remains available. He still posts to Statalist and may wish to comment.

    Comment


    • #3
      More recent threads like https://www.statalist.org/forums/for...-longer-appear imply that Sergiy's code was broken (accidentally!) by changes in official Stata.

      In #1 the diagonal striping has no statistical or graphical role and is just chosen on other grounds. If it is what you want or even what you need, your best guess is whatever software outside Stata that will do this and is easiest for you: a very weak answer, and a better one would be welcome. For what it's worth, Tufte's cogent criticism of such patterns conferred on me life-long resistance.

      Comment


      • #4
        I see. Thanks, Nick!

        Comment


        • #5
          Fred Lee ,

          the command mentioned by Nick Cox above that I wrote is twoway_parea and it is available from SSC (thanks to Kit Baum), to install:

          ssc install twoway_parea

          It modifies one specific type of twoway charts: area. It does not affect the other chart types, of which bar would be useful here. I see two possible ways to proceed with it:
          1. study how parea modifies area, and create pbar to modify bar in a similar fashion, or
          2. mimic bar chart with the help of area chart.
          Below is the second approach. With some more help from the members of this forum you can eliminate the few remaining cosmetic differences, such as the tiny gaps under the bars, or differences in axis tick values format.

          Hope this helps.

          Regards, Sergiy Radyakin



          Code:
          clear all
          version 16
          sysuse auto
          
          table foreign, c(mean price)
          
          input id x y
          1 0.7 0
          1 0.7 6072.4
          1 1.3 6072.4
          1 1.3 0
          1 0.7 0
          2 1.7 0
          2 1.7 6384.7
          2 2.3 6384.7
          2 2.3 0
          2 1.7 0
          end
          
          graph bar price, over(foreign) name(g1)
          
          twoway area y x, xlabel(1 "Domestic" 2 "Foreign") ///
              xscale(range(0.5,2.7)) xtitle("") ///
              ytitle("mean of price") name(g2)
          
          twoway parea y x, pattern(pattern4) ///
              xlabel(1 "Domestic" 2 "Foreign") ///
              xscale(range(0.5,2.7)) xtitle("") ///
              ytitle("mean of price") name(g3) 
          
          graph combine g1 g2 g3, rows(1)


          Click image for larger version

Name:	price.png
Views:	1
Size:	89.0 KB
ID:	1650324

          Comment


          • #6
            Thanks so much, Sergiy Radyakin

            Comment


            • #7
              The data in #1 are the only example in this thread and will serve as well as any other unless Fred Lee tells us about his real data.

              Strictly #1 does not look like a histogram to me at all.

              For what I guess the need may be, options include

              * horizontal bar chart or dot chart -- with plenty of space for text labels longer than those shown

              * no bar shading at all is a safe choice

              * sorting on the outcome is possible

              * dot chart axis doesn't have to start at zero if that is not needed or especially helpful

              * a grid seems overkill

              Code:
              clear 
              input str1 which whatever 
              A 78 
              B 89
              C 68 
              D 77 
              end 
              
              local opts ytitle(whatever)  ysc(titlegap(*5) r(. 100))
              
              set scheme s1color 
              graph hbar (asis) whatever, over(which) `opts' name(G1, replace) blabel(total)  yla(none,  nogrid) bar(1, bfc(none))
              graph hbar (asis) whatever, over(which, sort(1)) `opts' name(G2, replace) blabel(total) yla(none, nogrid) bar(1, bfc(none))
              
              local lineopts linetype(line) lines(lc(gs12) lw(thin)) 
              graph dot (asis) whatever, over(which) `opts' `lineopts' name(G3, replace) blabel(total)  
              
              local opts ytitle(whatever) ysc(r(60 100)) 
              su whatever, meanonly
              
              graph dot (asis) whatever, over(which, sort(1)) `opts' `lineopts' yla(`r(min)' `r(max)') exclude0 name(G4, replace) blabel(total) 
              
              graph combine G1 G2 G3 G4
              Click image for larger version

Name:	fred_lee.png
Views:	1
Size:	25.4 KB
ID:	1650450


              Comment

              Working...
              X