Announcement

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

  • -xtgraph - why won't -title- and -saving- work in my code?

    I am trying to execute the following code for several -xtgraph- charts. All the charts are executed but the title is not added and chart not saved to file. I would be grateful if someone could tell me what I have done wrong.


    Many thanks!

    Code:
    foreach v in SkinTodayChild SkinTodayParent SCORADExtTotal SCORADIntTotal SCORADSubPruritus SCORADSubSleepLoss ///
      SCORADSubTotal SCORADFinalTotal CDLQI_Score CDLQIP_Score IDQOL_Score FDLQI_Score  ///
      POEMP_Score POEMC_Score  DFI_Score{
    xtgraph `v',  av(median) bar(iqr) ///
    title ("`v' by Visit (Median & IQR)") ///
    saving("D:\x\chart`v'.png")
    }

  • #2
    -xtgraph- is from SSC. It looks like it's just a wrapper for -twoway line- and you are trying to pass extra graphing options for title() and saving() that aren't set up in the .ado file to pass along to the graph. You options are include :

    (1) edit the ado file (or contact the author about doing so but it was last updated in 2001)
    I edited this line (around line 700 in the ado file) and it worked (I added the `options' part to the code)

    Code:
    if "`graph'" == "" {
                         twoway line `avlist' `t2', `lineopts' `ytitle'  || `bartype' `lb' `ub' `t2' , `baropts' `options'
            }
    (I didnt check elsewhere in the code for places that this option could be added to restore/add this functionality.)
    or
    (2) graph using -twoway line- or -xtline-.
    Note that the 'saving() option in your example code is asking for 2 steps to save the gph file and then convert it to png, there isn't any reason to expect that to work in this program or any built-in stata program. You'd want to instead save the file (e.g.,
    Code:
    "...saving("myfile", replace)"
    ) and then use -graph export- to get your png file.

    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      I'd collapse to median and quartiles and plot those results directly. That would save a lot of time and frustration. My guess, for what's it worth.

      Sarah: You walked away from your previous thread http://www.statalist.org/forums/foru...ll-in-one-file

      That's a disincentive for me to give you much further time and effort.
      Last edited by Nick Cox; 11 Jan 2017, 10:29.

      Comment


      • #4
        I find xtgraph very useful but at the same time tricky myself. I found a workaround using addplot afterwards, which might work for you as well:

        first run xtgraph, e.g.:

        Code:
        xtgraph myvar, group(mygroupvar) level(90)
        then save and use addplot to e.g. modify achsis, add lines, add a title etc. All these I could somehow not run directly as xtgraph option.

        Code:
        graph save mygraph.gph, replace
        graph use mygraph.gph
        addplot: , xline(1) xline(2) xlabel(1(1)12) title(test)
        graph export myfile.png, replace
        Eric's solution might be more general, of course.

        Comment


        • #5
          If I understand the code correctly, xtgraph accepts wildcard options but only uses them in conjunction with the v7 option, i.e. to draw version 7 graphics. I don't imagine this is really intended behaviour.

          Comment

          Working...
          X