Announcement

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

  • radar chart showing different abilities of a player, with different poles representing different abilities

    Dear Statalist,

    I want to plot a radar chart to show different abilities of a player, with different poles representing different abilities (variables). The following example should be self explanatory of my question.

    ***************************************
    clear *
    set obs 10
    gen player =_n
    forvalues i=1/5 {
    gen ability`i'=runiform(1,10)
    }
    radar player ability1 ability2 /*each line representing one ability , not what i want*/

    ****what i want is for each player, a radar with a line connecting the 5 abilities, which can be done by reshaping:
    reshape long ability , i(player) j(ability_type)
    radar ability_type ability if player==1

    ****can i do the above without reshaping my data? maybe something like:
    clear *
    set obs 10
    gen player =_n
    forvalues i=1/5 {
    gen ability`i'=runiform(1,10)
    }
    someotherradar ability1 ability2 ability3 ability4 ability5 if player==1 /****is similar command available?****/
    ***************************************

    Thank you in advance for advice.

    Charlie

  • #2
    Sorry, this is not self-explanatory at all, as we can't see the graph and we have to search to find what radar is.

    https://www.statalist.org/forums/help#stata gives standards for a good question.

    I would imagine that "radar chart" is a good search term to find other programs that may do whatever you want.

    Comment


    • #3
      Do I correctly understand that you are able to produce the chart you want by reshaping the data to meet the needs of the radar command (a user-written command from SSC) but you instead want a way to produce it without reshaping the data?

      It seems to me you are making a problem where none exists. While reshaping will affect your data in memory, it will not affect the data saved on disk, so after the plotting you can clear the reshaped data and again use the original data to return the data in memory to its state prior to reshaping.

      Comment


      • #4
        Originally posted by William Lisowski View Post
        Do I correctly understand that you are able to produce the chart you want by reshaping the data to meet the needs of the radar command (a user-written command from SSC) but you instead want a way to produce it without reshaping the data?

        It seems to me you are making a problem where none exists. While reshaping will affect your data in memory, it will not affect the data saved on disk, so after the plotting you can clear the reshaped data and again use the original data to return the data in memory to its state prior to reshaping.
        Thanks for your reply William. Your understanding is correct. But the reshaping approach may not meet all my requirements. I reproduce my example below .

        ***********************
        ssc install radar
        clear *
        set obs 10
        gen player =_n
        forvalues i=1/5 {
        gen ability`i'=runiform(1,10)
        }
        radar player ability* /*please see attached graph. instead of having one line for one ability, i need one line for one player (there are 10 players). this can be done by reshaping but seemingly with limitation, as illustrated below*/

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	32.1 KB
ID:	1412286


        reshape long ability , i(player) j(ability_type)
        radar ability_type ability if player==1 /*this plots the line for one player, but i need lines for other players on the same chart (i.e. a pentagon radar with 10 lines) */

        *************************

        Grateful for advice.

        Charlie.

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Sorry, this is not self-explanatory at all, as we can't see the graph and we have to search to find what radar is.

          https://www.statalist.org/forums/help#stata gives standards for a good question.

          I would imagine that "radar chart" is a good search term to find other programs that may do whatever you want.
          Thank you for the suggestion Nick. Before resorting to other programs, I would like to know whether Stata can do it - because using other programs may interrupt the automation process where I use Stata for data importing, management and getting outputs.

          Comment


          • #6
            #5 Yes, I understand the desire to keep everything in Stata. My suggestion was intended to mean search for Stata programs.

            For my part, I find these radar charts singularly useless and have never wanted to program them. The only interest I can recall in them in the Stata community is the program you already know about, so I can't suggest anything else (apart from a completely different kind of graph).

            Of course, no pattern can be expected in random data but why wire in the identifiers of the people in that order?

            Comment


            • #7
              Note that Charlie is asking about datasets with this kind of form:


              Code:
                   +---------------------------------------------------------------+
                   | player   ability1   ability2   ability3   ability4   ability5 |
                   |---------------------------------------------------------------|
                1. |      1   9.319409   8.142171   7.020389   3.432777   1.445766 |
                2. |      2   3.993707   6.674836   8.683037    9.99513   2.664865 |
                3. |      3   7.965716   1.840676   8.709027   7.993804     2.6566 |
                4. |      4   1.936717   1.324697   2.581272    1.96187   7.576636 |
                5. |      5    4.04554   1.855764   5.127655   5.159319   2.727305 |
                   |---------------------------------------------------------------|
                6. |      6   1.180202     3.2612   4.388908   9.203662   4.333987 |
                7. |      7   2.616032   1.633147   4.042758   9.722306   3.245707 |
                8. |      8   6.638062   1.974043   4.423301   2.040377   9.460052 |
                9. |      9   4.582385   6.230533   5.457447   3.310153    3.06735 |
               10. |     10   4.483518     3.1494   2.410387   6.949878    3.06243 |
                   +---------------------------------------------------------------+
              I think's it generic across Stata graphics that you can easily connect values of a variable, but to make connections across each observation is really hard without a reshape.

              Comment


              • #8
                Reading help radar and looking at the graph and description in post #4 makes the problem transparent.

                The radar command requires an observation for each "axis" on the radar plot, and a variable for each "star".

                The desired graph will have an "axis" for each ability type and a "star" for each player, so it will require the data to consist of an observation for each ability type and a variable for each player.

                The data as given has a variable for each ability type and an observation for each player.

                Thus, two applications of reshape will be necessary to transform the data into what is needed to produce the desired plot. (Perhaps xpose would do this as well, but the tool I know is the reshape command so it's the tool I will use.)

                Code:
                // sample data one observation for each player
                clear *
                set obs 10
                gen player =_n
                forvalues i=1/5 {
                gen ability`i'=runiform(1,10)
                }
                list if player==1
                // one observation for each combination of player and ability type
                reshape long ability, i(player) j(type)
                list if player==1
                // one observation for each ability type
                reshape wide ability, i(type) j(player)
                rename (ability#) (player#)
                list type player1
                radar type player*
                Click image for larger version

Name:	radar.png
Views:	1
Size:	234.9 KB
ID:	1412311

                Let me add that until post #4 nothing was stated about wanting "a pentagon with 10 lines" - the examples in post #1 were "if player==1".

                Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

                The better you do at helping others understand your problem, the more likely others are to be able to help you solve your problem.
                Last edited by William Lisowski; 27 Sep 2017, 12:17.

                Comment


                • #9
                  Please consider a parallel coordinates plot as an alternative to the radar plot.
                  Code:
                  ssc d parplot
                  Building on William's example:
                  Code:
                  clear
                  set obs 10
                  gen player = _n
                  forvalues i = 1/5 {
                    gen ability`i' = runiform(1,10)
                  }
                  parplot ability*, over(player) legend(row(2))
                  Click image for larger version

Name:	parplot.png
Views:	1
Size:	64.1 KB
ID:	1412325

                  Comment


                  • #10
                    Thank you all for the help! My apologies for not making the problem clearer.

                    Comment


                    • #11
                      Thanks to Friedrich for mentioning parplot (SSC). Most of its work is to reorganize the data temporarily to make connections across observations possible, so it's no exception to the point in #7.

                      Comment

                      Working...
                      X