Announcement

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

  • connect paired dot in scatter plot

    Hi there,

    I'm working on a descriptive scatter plot where I need to show values of two variables, X1, X2. I would like to show the scatter plot of these two variables in pairs as follows
    Click image for larger version

Name:	illustration.png
Views:	1
Size:	31.7 KB
ID:	1513271


    The data looks something like this :
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(X1 X2) float Y
    76.74 19.11  1
    67.85 22.49  2
    60.44 21.65  3
    36.75 24.56  4
    77.78 44.19  5
     44.6 17.71  6
    66.17 23.02  7
    41.61 19.19  8
    26.77 17.57  9
    35.05 16.97 10
    44.88 19.64 11
    47.99 21.61 12
    61.63 34.04 13
    40.27    22 14
    50.07 21.12 15
    end

    I tried scatter plot, but was not able to link the paired dots. here is my try :

    twoway (scatter Y X1 ) (scatter Y X2 )


    I would really appreciate if anyone could offer insights on how to create the above-mentioned graphs!

    Thanks!

    Donghui

  • #2
    One thing that's confusing is that you need TWO y variables and only one X variable, and you have the opposite.

    Besides that, you need to add a third plot, the rspike plot, to draw the lines: twoway (rspike X1 X2 Y)

    Comment


    • #3
      The variable names are indeed distracting, but developing Sergio's suggestion I think
      Code:
      scatter X1 X2 Y  || rspike X1 X2 Y , legend(order(1 2) pos(3) col(1)) xla(1/15)
      is close to what you need.

      Comment


      • #4
        Thanks a lot !!

        Comment

        Working...
        X