Announcement

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

  • line connecting dots in graph dot

    Dear statalist users,

    I am trying to add a line connecting the pair dots for each country in the figure attached. I don't want the default line that goes from the beginning to the end of the x axis, but a line just connecting the two dots. Do you have any idea whether I can do this? I think it may be changing/adding something in the line of code before the last one... I have checked the help file but I don't find the way to do it.

    I believe the line connecting the pair of dots for each country will improve the visualisation by aiding interpretation. I also highly appreciate if you want to provide input regarding whether you believe the figure looks good as it is now, or whether the line connecting the dots will improve the data visualisation.

    I also attach the code that I used to create the figure.

    Thank you in advance for your input.

    Best wishes,
    Ana

    Ana Méndez
    PhD candidate
    [learning #dataviz]


    Code:
    graph dot outcome_prop_2010 outcome_prop_2017 if pickone_outcome_sample_final==1 & sample_final==1, ///
    over(country, label(angle(h) labsize(vsmall)) sort(sorting_var)) scheme(s1mono) ///
    legend(size(vsmall) label(1 "2010") label(2 "2017") ring(0) position(8) cols(1) symy(1) symx(2) textw(1) bmargin(large) region(lstyle(none) color(none)) linegap(*5)) ///
    linetype(line) lines(lcolor(none) lw(vvthin)) ///
    ylabel(0(2)22,labsize(small) angle(horizontal))
    Click image for larger version

Name:	dot_graph_outcome_horizontal copia.jpg
Views:	1
Size:	116.7 KB
ID:	1563424

    Last edited by Ana ML; 14 Jul 2020, 13:43.

  • #2
    It would be easier for us if you gave us an example dataset to work with. Now we have to guess what your data looks like, and there is no guarantee we guess correctly. We ask you to provide examples using dataex. Type in Stata help dataex. Also see the FAQ.

    Anyhow here is my guess. It requires the user written labmask command. You can find and install it by typing in Stata search labmask and follow the links.

    Code:
    sysuse citytemp.dta, clear
    set scheme s1color
    collapse tempjan tempjuly, by(division)
    
    egen Division = rank(-tempjan)
    labmask Division, values(division) decode
    
    twoway rspike tempjan tempjuly Division,       ///
        horizontal ylab(1/9, val angle(0))         ///
        ytitle("")                                 ///
        xtitle("Average temperature (Fahrenheit)") ///
        legend(order(2 "January" 3 "July"))     || ///
        scatter Division tempjan                || ///
        scatter Division tempjuly
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.3 KB
ID:	1563436
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Dear Maarten,

      Thank you for your answer, and apologies for not sending an example dataset - I wasn't aware it was needed, I'll make sure to send it next time.

      You made a correct guess about how my data looks like and your suggestion worked perfectly for my needs - thank you so much for your input. I used the same coding strategy and changed rspike to pcarrow, adding a nice arrow pointing from the estimate for the first time point to the estimate of the second.

      Best wishes,
      Ana



      Comment


      • #4
        See also https://journals.sagepub.com/doi/pdf...867X0500500214

        Comment

        Working...
        X