Announcement

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

  • Is it possible to combine binscatter and vioplot?

    Vioplot works on categorial x axis. binscatter makes continuous, discrete. I am looking to have a histogram shown at each point in a binscatter point the same way vioplot does it. Is that possible?

  • #2
    I find this puzzling. I know but many readers will not that vioplot and binscatter are community-contributed commands on SSC. See FAQ Advice #12 for our longstanding request to explain that

    Beyond that, vioplot does not draw histograms as far as I know, so what you do seek precisely?

    A short answer is that there isn't a way to combine them as such without hacking at the code of one to include the other.

    Binning one variable first is easier than drawing histograms or other distribution displays side by side. What you want may be as simple as binning a continuous variable first, and then calling up vioplot.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      I find this puzzling. I know but many readers will not that vioplot and binscatter are community-contributed commands on SSC. See FAQ Advice #12 for our longstanding request to explain that

      Beyond that, vioplot does not draw histograms as far as I know, so what you do seek precisely?

      A short answer is that there isn't a way to combine them as such without hacking at the code of one to include the other.

      Binning one variable first is easier than drawing histograms or other distribution displays side by side. What you want may be as simple as binning a continuous variable first, and then calling up vioplot.
      The problem with your solution is that it vioplot's x labels are evenly spaced out but it could be the case that x axis points are actually 0.1 ,0.2 and 20 . two of them closer and one far.

      Comment


      • #4
        Indeed, but if a histogram must fit at 0.1 and another at 0.2 how is that to be done without an enormous gap before 20? Besides, if I am the reader and you show me just those three histograms, I am going to ask for more detail or another graph.

        There are other commands in this territory. I am more familiar with stripplot from SSC.

        Here I binned age from the nlswork data into quintiles and plot distributions against the median of each quintile. One possibility which I like but not many others do is just a quantile plot. It is easy to combine that with a reference line summarizing each distribution. Here the reference line shows the mean of ln wage, which is the geometric mean shown on log scale.

        More orthodox by many standards is a dot plot (approximate histogram) and box plot alongside.

        More could be done to improve titles, but the point is that stripplot respects x axis values, as could be done on purpose in any command you wrote yourself.

        Code:
        webuse nlswork, clear 
        
        xtile bin_age = age, nq(5)
        egen show_age = median(age), by(bin_age)
        
        stripplot ln_wage, cumul cumprob over(show_age)  refline vertical centre height(3) mc(blue) name(qplot, replace)
        
        stripplot ln_wage, stack  over(show_age) ms(oh)  msize(small) width(0.05)  vertical height(3) mc(blue%20) name(dotplot, replace) box(barw(0.4)) pctile(0) boffset(-0.4)
        Click image for larger version

Name:	williams_qplot.png
Views:	1
Size:	36.0 KB
ID:	1683943
        Click image for larger version

Name:	williams_dotplot.png
Views:	1
Size:	62.8 KB
ID:	1683944


        Comment

        Working...
        X