Announcement

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

  • How to give different color for all the scatter plots in a graph?

    Hello everyone, I am using Stata 16.0, The data is in wide format with 29 observations.
    It is a National data with state variables.
    I would like to create a twoway scatter plot with case fatality rate (cfr) and case positivity rate (cpr) of covid, among all Indian states with death rate as weight.
    I have used the following code. I would like to colour all the 29 states mentioned in the data with different colors. How can I do that?
    Code:
    twoway (scatter cpr cfr, mfcolor(blue) msymbol(none) mlabel(dummy) mlabposition(6) mlabgap(4) mlabsize(vsmall) mlabangle(90) mlabcolor(black)) (scatter cpr cfr [aweight=death])
    Thanks in advance
    Last edited by Rukman Mecca; 30 Jan 2021, 03:58.

  • #2
    You would need to create 29 variables and then specify different colours. The command separate makes the first easier. Use the option . veryshortlabel explained at https://www.stata-journal.com/sjpdf....iclenum=gr0023

    I must say that I advise against this. Sure, your plot will look suitably colourful, but to what useful end?

    Big problem for the reader: You will need a legend with 29 items to explain, and it will take up a lot of space.

    Big problem for the designer: Getting 29 colours different enough to be easily distinguished, bearing in mind problems with say red-green colour blindness.

    Small problems for readers. There are at least two kinds of questions with "look up". First kind: This data point is interesting or striking -- so I need to match its colour with the legend to find out which state it is. Second kind: I am interested in Kerala (say). Where is it on the graph? Is either kind of question really easy to answer with this design?

    If this were my data I would

    1. Use the two-letter abbreviations that are standard (you are probably familiar with them already but I had to Google to find them: https://kb.bullseyelocations.com/art...ia-state-codes) as marker labels

    2. Probably go for a portfolio of about 4 plots, in each of which I would identify say 7 or 8 states with the others as backdrop.

    The design discussed in https://www.statalist.org/forums/for...ailable-on-ssc is available in principle but a portfolio of 29 scatter plots would, I fear, be too many.

    (Your design is already complicated with marker labels as well as weights. And you're struggling by making the marker labels very small...)
    Last edited by Nick Cox; 30 Jan 2021, 04:37.

    Comment


    • #3
      Thank you Nick Cox Really appreciate your effort to answer this. It was partly helpful. Based on the article you shared, I made this command. It worked for outline of the scatter plots. Is it possible to change the filling of the plots with different colour?
      Following is the command I used,
      Code:
      twoway scatter cfr cpr [aweight=death], mfcolor(gs0 gs1 gs2 gs3 gs4 gs5 gs6 gs7 gs8 gs9 gs10 gs11 gs12 gs13 gs14 gs15 gs16) yla(0 1 2 3) xla(0 5 10 15) || scatter cfr cpr, mlabel(dummy)
      This is the graph I obtained with this command

      Click image for larger version

Name:	Graph.png
Views:	1
Size:	47.2 KB
ID:	1592085

      Comment


      • #4
        As stated in #2 the only easy way to get different colours is to create separate variables.

        Comment

        Working...
        X