Announcement

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

  • Scatter plot and bubble size

    Hello. I'm working on creating a bubble plot in Stata, and I have a question about something I couldn't solve.

    The reference code is as follows:

    Code:
    clear all
    input x y weight group
    1 1 1 1
    2 1 10 1
    1 2 100 2
    2 2 1000 2
    end
    
    * #1
    scatter y x [w=weight], name(A)
    
    * #2
    twoway (scatter y x if group==1 [w=weight]) ///
    (scatter y x if group==2 [w=weight]), name(B)
    I want to give weight to the bubble size, as in #1, where the bubble size criterion is the total value, and group it as shown in #2.
    In other words, I want to obtain results where, as in #1, the bubble size is divided into 4 groups and the color groups are divided into 2.

    Please help me.

    Thank you.

  • #2
    Discussed in https://journals.sagepub.com/doi/10....36867X20931008.

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Andrew Musau,

      Thank you very much!!

      The code that solved the problem is as follows, and I believe I just need to apply it to the data I have.

      Code:
      separate y, by(group)
      twoway scatter y? x [w=weight], mcolor(red blue) legend(order(1 "Y" 2 "X") row(1))
      The link you provided for the reference paper seemed to be paid, but I found it available for download on Google Scholar. Link: https://www.rama.mahidol.ac.th/ceb/s...2.pdf#page=245

      Comment


      • #4
        Originally posted by Inho Lee View Post

        Andrew Musau,

        Thank you very much!!

        The code that solved the problem is as follows, and I believe I just need to apply it to the data I have.

        Code:
        separate y, by(group)
        twoway scatter y? x [w=weight], mcolor(red blue) legend(order(1 "Y" 2 "X") row(1))
        The link you provided for the reference paper seemed to be paid, but I found it available for download on Google Scholar. Link: https://www.rama.mahidol.ac.th/ceb/s...2.pdf#page=245
        Oh, I have one more question. After applying different-sized circles, I'm trying to add mlabel, but the weight of the circles is not being applied correctly. Mlabel appears with the values, but the circle sizes disappear. The code is as follows.

        Code:
        twoway scatter y? x [w=weight], mcolor(red blue) legend(order(1 "Y" 2 "X") row(1)) mlabel(weight weight)
        Ultimately, I want to draw circles according to the relative weights and display the values as labels.

        Comment


        • #5
          Originally posted by Inho Lee View Post

          Oh, I have one more question. After applying different-sized circles, I'm trying to add mlabel, but the weight of the circles is not being applied correctly. Mlabel appears with the values, but the circle sizes disappear. The code is as follows.

          Code:
          twoway scatter y? x [w=weight], mcolor(red blue) legend(order(1 "Y" 2 "X") row(1)) mlabel(weight weight)
          Ultimately, I want to draw circles according to the relative weights and display the values as labels.
          I left the question out of confusion, but after searching on the internet, it seems like I can solve it with the following code.

          Code:
          twoway (scatter y? x [w=weight], mcolor(red blue) legend(order(1 "Y" 2 "X") row(1))) ///
          (scatter y? x, mcolor(red blue) mlabel(weight weight))
          I apologize for the messiness in the question and answer.

          Comment

          Working...
          X