Announcement

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

  • Adding Labels To A Line Graph For The Overlaying Lines

    I have a two-way line graph in which there are a lot of line overlay. Is there a way to add a label to each line to show the number of overlaying lines?

    Code:
     levelsof date2, local(datevalues)
      levelsof assetid2, local(idvalues)
      local linecmd " "
      foreach i of local datevalues {
         foreach j of local idvalues {
          local linecmd "`linecmd' (line price blocknumber if date2 == `i' & assetid2 == `j' , connect(stepstair)  xtitle(Blocks) ytitle(Price($/MWH))) "
        }
        }
      
      di "`linecmd'"
      twoway  `linecmd',  legend(off) title(Hourly Bids Over Two Months (Feb-March-2014) For Hour=18- SH1, tstyle(size(medium))) 

    Click image for larger version

Name:	SH1-hour 18- over blocks.png
Views:	1
Size:	84.0 KB
ID:	1330144

    In this graph there are around 60 lines. I want to have a label on each line that shows the number of overlaying lines.

    Thanks,
    Hossein

  • #2
    Have you considered drawing the lines in individual panels? I don't know if that defeats the purpose of the graph but the lines would be easier to see.

    You didn't show us your data so I couldn't test the following command. 60 panels is a lot but the graph may be legible.
    Code:
    twoway line price blocknumber, by(date2 assetid2, compact) connect(stepstair)

    Comment


    • #3
      The 60 panels would be a lot and difficult to see the differences. I prefer having them in one single graph. Here is a piece of data:


      Code:
      date                          blocknumber            price
      02/01/2014                         0                 0
      02/02/2014                         6               946.93
      02/02/2014                         5               920.89
      02/02/2014                         4               325.85
      02/02/2014                         3               38.84
      02/02/2014                         2               20.57
      02/02/2014                         1               14.26
      02/02/2014                         0                0
      02/03/2014                         6               949.86
      02/03/2014                         5               948.78
      02/03/2014                         4               825.77
      02/03/2014                         3               38.48
      02/03/2014                         2               20.35
      02/03/2014                         1               14.14
      02/03/2014                         0                   0
      Code:
       levelsof date, local(datevalues)
        local linecmd " "
        foreach i of local datevalues {
            local linecmd "`linecmd' (line price blocknumber if date == `i',connect(stepstair))"
          }
        twoway  `linecmd',  legend(off)
      There are 60 dates (2 months).
      Last edited by Hossein Hosseini; 10 Mar 2016, 00:23.

      Comment


      • #4
        Did you try the command I proposed? It is difficult to see the differences in your graph because it is impossible to distinguish individual lines.

        Please use the dataex package from SSC to share the excerpt from your data. Section 12 of the FAQ explains how to install and use dataex.

        Comment


        • #5
          On possibility is to add a scatterplot to your graph using the count as a label on the scatterplot. You have control over the marker symbol used in the scatterplot (dot, diamond, nothing) as well as the placement of the marker label (count). But this is start:

          Code:
          clear
          input str12 date                          blocknumber            price
          "02/01/2014"                         0                 0
          "02/02/2014"                         6               946.93
          "02/02/2014"                         5               920.89
          "02/02/2014"                         4               325.85
          "02/02/2014"                         3               38.84
          "02/02/2014"                         2               20.57
          "02/02/2014"                         1               14.26
          "02/02/2014"                         0                0
          "02/03/2014"                         6               949.86
          "02/03/2014"                         5               948.78
          "02/03/2014"                         4               825.77
          "02/03/2014"                         3               38.48
          "02/03/2014"                         2               20.35
          "02/03/2014"                         1               14.14
          "02/03/2014"                         0                   0
          end
          
          bysort blocknumber: egen count=count(blocknumber)
          *not sure if your block counts are by date or not, if so, then:
          *        bysort date blocknumber: egen count=count(blocknumber)
          
          levelsof date, local(datevalues)
            local linecmd " "
            foreach i of local datevalues {
                local linecmd "`linecmd' (line price blocknumber if date == "`i'",connect(stepstair)) (scatter price blocknumber if date == "`i'", mlabel(count))"
              }
            twoway  `linecmd',  legend(off)
          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment

          Working...
          X