Announcement

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

  • Can you make ridgeline plots (aka joyplots) in Stata 16?

    Hi!

    I stumbled on this data visualization page https://www.data-to-viz.com/ and realized that ridgeline plots (formerly known as joyplots) would be very useful for my current project. Is there a way to do them with Stata 16?

    Here you find an example done with R

    Click image for larger version

Name:	ggridges-visualize-distribution-in-r-density-logo-1.png
Views:	1
Size:	171.5 KB
ID:	1560169


    taken from https://www.datanovia.com/en/blog/el...ing-ridgeline/

  • #2
    Here is one attempt. This uses -mylabels- to make easy to specify the axis labels (ssc desc mylabels):

    Code:
    clear
    import delimited "https://raw.githubusercontent.com/awhstin/temperaturesv2/master/OHARE-NCDC-2017.csv"
    
    gen month = substr(date, 6,2)
    destring month, replace
    range attemp -10 90
    levelsof  month, local(levels)
    
    foreach l of local levels {
        kdensity tavg if month == `l',  gen(x`l' d`l') nograph at(attemp)
        
        gen yaxis`l' =  `l'/24 
        replace d`l'  = d`l' + yaxis`l'
    
        local g "`g' rarea d`l' yaxis`l'  x`l' , fc(black%70)  lc(black)  lw(vvthin) || "
    }
    disp "`g'"
    mylabels 1(1)12 , local(a) myscale(@/24)
    twoway  `g'  , legen(off)  ylabel(,nogrid)   xlabel(, nogrid) xlabel(-10(20)90) /// 
      ylabel(`a')   ytitle(Month) xtitle(Average Temperature)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	38.3 KB
ID:	1560232

    Comment


    • #3
      I quite like these too although

      (1) I am not clear than overlap or even occlusion is a feature -- the attraction there seems to lie in something irrelevant, an evocation of rolling topography, perhaps.

      (2) the colour gradient in #1 is clever, not to say cute, but not to all tastes.

      A shift from lines to areas as standard for density functions seems to be in progress.

      Comment


      • #4
        Thank you so much Scott Merryman ! This is what I had in mind but was unsure how to best get it done in Stata.

        Nick Cox:
        1) one can play around with the spacing (by changing /24 in the example) such that there's no overlap.
        2) I think that depending on context, the color shading would be helpful. The particular choice of colors in the R-example goes back to the original Data Novia blog post. It may not be to all tastes, like any choice of colors. Whether we think of colors are "cute" is another discussion.

        Comment


        • #5
          "cute" is a double-edged word, at least the way I use it.

          Comment


          • #6
            Using Rsource or Rcall (both from SSC) is another option.
            __________________________________________________ __
            Assistant Professor, Department of Biostatistics and Epidemiology
            School of Public Health and Health Sciences
            University of Massachusetts- Amherst

            Comment


            • #7
              That is a really interesting plot!

              Comment

              Working...
              X