Announcement

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

  • Highlighting one data point in a coefficient plot.

    Hi there,

    I am using Stata 18 and the coefplot package from SSC.

    I have created a coefficient plot of sleep duration over a two-week period using a matrix (First row of matrix: mean. Second row of matrix: standard error). Code is below:
    Code:
    set scheme s1mono
    coefplot mat(spring_mat), se(2) vertical xlab(1 "Sun" 2 "Mon" 3 "Tue" 4 "Wed" 5 "Thur" 6 "Fri" 7 "Sat" 8 "Sun" 9 "Mon" 10 "Tue" 11 "Wed" 12 "Thur" 13 "Fri" 14 "Sat" 15 "Sun") xtitle("Day", height(5)) ytitle("Mean sleep duration (hours) +/-SEM", height(5)) graphregion(color(white)) plotregion(lc(white)) ylabel(, nogrid)
    I have been asked to highlight somehow that the middle Sunday is the Sunday of the Spring clock change. I've tried updating the x axis label for the middle Sunday to "Clock change Sun" which crudely did the job, but to fit that in I then had to angle the x labels which means the graph takes up a lot more space.

    I was therefore wondering whether there is a way to change the marker symbol for just the middle Sunday on my graph (graph will be black & white so no point changing the colour)? Or if you have any better suggestions of how to highlight that the middle Sunday is the Sunday of the clock change?

    Thank you in advance!

    Mel

  • #2
    Data example?

    Comment


    • #3
      My matrix & resulting graph look like this (not my real data):
      spring_mat1 spring_mat2 spring_mat3 spring_mat4 spring_mat5 spring_mat6 spring_mat7 spring_mat8 spring_mat9 spring_mat10 spring_mat11 spring_mat12 spring_mat13 spring_mat14 spring_mat15
      9.0 8.6 8.4 8.5 8.4 8.6 9.3 8.0 8.7 8.5 8.6 8.7 8.7 9.0 9.2
      0.03 0.04 0.03 0.04 0.03 0.04 0.03 0.04 0.03 0.04 0.03 0.04 0.03 0.04 0.03
      Click image for larger version

Name:	fake_graph.png
Views:	1
Size:	22.3 KB
ID:	1751886

      Comment


      • #4
        Code:
        clear matrix
        mat X= [9.0, 8.6, 8.4, 8.5, 8.4, 8.6, 9.3, 8.0, 8.7, 8.5, 8.6, 8.7, 8.7, 9.0, 9.2 \0.03, 0.04, 0.03, 0.04, 0.03, 0.04, 0.03, 0.04, 0.03, 0.04, 0.03, 0.04, 0.03, 0.04, 0.03]
        mat Xh= J(rowsof(X), colsof(X), .z)
        mat Xh[1,8]= X[1,8]
        mat Xh[2,8]= X[2,8]
        mat X[1,8]= .z
        mat X[2,8]= .z
        
        
        coefplot (mat(X), se(2) color(gray) ciopts(lc(gray)))  \ ///
        (mat(Xh),  offset(0) se(2) msymbol(S) color(black) ciopts(lc(black))  ///
        ytitle("Mean sleep duration (hours) +/-SEM", height(5))), ///
        vert nokey xtitle("")  ylabel(, nogrid) nokey ///
        xlab(1 "Sun" 2 "Mon" 3 "Tue" 4 "Wed" 5 "Thur" 6 "Fri" 7 "Sat" ///
        8 "{bf:Sun}" 9 "Mon" 10 "Tue" 11 "Wed" 12 "Thur" 13 "Fri" 14 "Sat" 15 "Sun")
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	18.2 KB
ID:	1751935

        Last edited by Andrew Musau; 01 May 2024, 11:00.

        Comment


        • #5
          Amazing! Thank you so much for your help.

          Comment

          Working...
          X