Announcement

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

  • Applying different colors to data points when using aaplot

    Hi Stata Users,
    I am using a Stata user written command aaplot and would like to colour code the points using the category variable. I am using the syntax and the dataset below


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(value_2014 growth category)
    21  1 1
    11  5 1
    20  6 2
    16  7 3
    14  3 3
    18  3 1
    19  1 2
    20  4 3
    21 10 1
    22 11 2
    10  2 3
    17  5 3
    18  9 3
    12  7 3
    11  8 2
    10  6 2
    14  5 2
    17  7 1
    20 11 1
    22 12 1
    21 15 1
    15  2 1
    15  5 2
    17  8 2
    19  9 2
    10  6 3
    10  4 3
    14  4 3
    20  5 1
    16  7 2
    19  8 3
    18  9 1
    10  3 1
    11  9 1
    12  8 2
    14  7 2
    15  3 2
    18  5 3
    19  5 1
    13  3 2
    14  9 3
    15  2 3
    15  1 3
    16 10 2
    17 12 1
    19 11 2
    18 16 3
    12  6 2
    10  9 2
    20  2 2
    end

    Code:
    aaplot growth value_2014
    Thanks in advance!

  • #2
    aaplot is from SSC. You could do something like:

    Code:
    separate growth, by(category) veryshortlabel 
    aaplot growth value_2014, ms(none) backdrop(scatter growth? value_2014, ms(Oh + Th)) xla(10(2)22) legend(on order(1 2 3) row(1) ring(0) pos(11))

    Click image for larger version

Name:	okiya.png
Views:	1
Size:	31.1 KB
ID:	1764986


    There's plenty of scope to improve on that: define variable labels, round results to fewer decimal places, and so on.

    Comment


    • #3
      Thanks Nick Cox for the incredible help. This is really helpful.

      Comment


      • #4
        I am trying to have all points to be circles using the syntax below but the results aren't as intended

        Code:
        separate growth, by(category) veryshortlabel 
        aaplot growth value_2014, ms(none) backdrop(scatter growth? value_2014, ms(Oh + Oh + Oh)) xla(10(2)22) legend(on order(1 2 3) row(1) ring(0) pos(11))
        Any help will be greatly appreciated.

        Comment


        • #5
          You're asking for open circie, plus, open circle, plus, open circle. So, don't ask for plus. In this context the + does not mean "and". It means that you want the marker symbol to be a plus sign +.

          Code:
          ms(Oh Oh Oh)
          or

          Code:
          ms(Oh ..)

          Comment


          • #6
            Thanks so much Nick Cox for the guidance. I sincerely appreciate your help.

            Comment


            • #7
              Your data in #1 show many identical data points. In these circumstances circles even with different colours can't work well unless you make them have different sizes or add jitter.

              Comment


              • #8
                Thank you so much for the advice - it makes sense to use different symbols to address overlap of points

                Comment


                • #9
                  I have encountered an outlier that I would like to exclude in the analysis. Below is a modified version of data to reflect the case
                  Code:
                  * Example generated by -dataex-. For more info, type help dataex
                  clear
                  input byte(value_2014 growth category)
                  21  1 1
                  11  5 1
                  20  6 2
                  16  7 3
                  14  3 3
                  18  3 1
                  19  1 2
                  20  4 3
                  21 10 1
                  22 11 2
                  10  2 3
                  17  5 3
                  18  9 3
                  12  7 3
                  11  8 2
                  10  6 2
                  14  5 2
                  17  7 1
                  20 11 1
                  22 12 1
                  21 15 1
                  15  2 1
                  15  50 2
                  17  8 2
                  19  9 2
                  10  6 3
                  10  4 3
                  14  4 3
                  20  5 1
                  16  7 2
                  19  68 3
                  18  9 1
                  10  3 1
                  11  9 1
                  12  8 2
                  14  7 2
                  15  3 2
                  18  5 3
                  19  5 1
                  13  3 2
                  14  9 3
                  15  2 3
                  15  1 3
                  16 10 2
                  17 12 1
                  19 11 2
                  18 16 3
                  12  6 2
                  10  9 2
                  20  2 2
                  end

                  I am using the following code but it seems not to work
                  Code:
                   separate growth, by(category) veryshortlabel  aaplot growth value_2014 if growth < 20, ms(none) backdrop(scatter growth? value_2014, ms(Oh + Th)) xla(10(2)22) legend(on order(1 2 3) row(1) ring(0) pos(11))
                  Thanks in advance
                  Last edited by Stephen Okiya; 04 Oct 2024, 04:54.

                  Comment


                  • #10
                    You need to apply the if qualifier within the addplot() call too.

                    Comment

                    Working...
                    X