SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Axis labels on graph

    Posted Mon September 16, 2024 07:08 PM

    I'm trying to generate a simple bar graph.  My syntax is:

    GGRAPH
      /GRAPHDATASET NAME="graphdataset" VARIABLES=ypll_75 MISSING=LISTWISE REPORTMISSING=NO
      /GRAPHSPEC SOURCE=INLINE.
    BEGIN GPL
      GUIDE: axis(dim(1), label("Years of potential life lost"))
      GUIDE: axis(dim(2), label("Frequency"))
      GUIDE: text.title(label("Frequency of Years of potential life lost - 2019-2021: Hispanic/Latino"))
      ELEMENT: interval(position(summary.count(bin.rect(ypll_75))), shape.interior(shape.square))
    END GPL.

    The bar graph gets generated fine, but the Y axis - which is the frequency count - has labels that include one digit after the decimal point, such as 10.0, 20.0, 30.0, etc.  Since the Y axis is just frequencies, I want the labels to be simply 10, 20, 30, etc.

    How do I get rid of that ".0"?



    ------------------------------
    Urban Landreman
    ------------------------------


  • 2.  RE: Axis labels on graph
    Best Answer

    Posted Tue September 17, 2024 09:43 AM

    Hi @Urban Landreman. You can set the precision of Y-Axis tick labels by opening the chart in the Chart Editor, selecting the Y-Axis labels by clicking once on one of them, then opening Chart Editor Properties dialog and using the Number Format tab there to set the precision. See the screen shot below.

    Best,

    Curtis

    How to set the decimal precision on Y-Axis labels


    ------------------------------
    Curtis Browning
    SPSS Statistics Architect
    ------------------------------



  • 3.  RE: Axis labels on graph

    Posted Tue September 17, 2024 09:48 AM
    In many cases, the precision of the marker labels is derived from the decimals setting of the variable, so try changing the decimals setting to zero.

    --





  • 4.  RE: Axis labels on graph

    Posted Tue September 17, 2024 10:13 AM

    In this case the Y-Axis is Count and the X-Axis variable precision is already set to zero decimals, so either a chart template or a post-creation change was needed. 

    I do think that it is an error to set the decimal precision to 1 for Counts, so I have filed an enhancement request to get that changed.

    Best,



    ------------------------------
    Curtis Browning
    SPSS Statistics Architect
    ------------------------------



  • 5.  RE: Axis labels on graph

    Posted Tue September 17, 2024 11:15 AM

    Since the decimal setting is only for the display, not how and what is stored, I usually put a TEMPORARY command before the GGRAPH syntax.

    With v1 defined in whatever format, F4.3 say, the following would set the axis where v1 is used with no decimals:

    TEMPORARY.
    FORMATS v1(F4).
    GGRAPH
    /GRAPHDATASET...
    .
    .

    END GPL.

    An easy way to avoid the format definitions? 

    .

     



    ------------------------------
    Robert
    ------------------------------



  • 6.  RE: Axis labels on graph

    Posted Tue September 17, 2024 12:01 PM

    That works well if one is using a variable on the axis. In your original example though there was only the `ypll_75` variable on the x-axis and Frequency (Count) on the y-axis. In cases like that only a chart template or manual editing will affect the format of the y-axis tick labels.

    Best,



    ------------------------------
    Curtis Browning
    SPSS Statistics Architect
    ------------------------------



  • 7.  RE: Axis labels on graph

    Posted Tue September 17, 2024 09:50 AM

    Thanks for the helpful reply.

    I see that that does the trick.

    However, there must be a way to specify that in GPL, right?  My goal is to generate a bunch of graphs programmatically.  I hate to have to go back and tweak each graph one-by-one.

    I'll do that if I have to, but I sure hope that there's a specification I can do in GPL.

    Thanks again. 



    ------------------------------
    Urban Landreman
    ------------------------------



  • 8.  RE: Axis labels on graph

    Posted Tue September 17, 2024 09:58 AM
    Besides changing the variable format, you can set display properties with a custom chart template.  You create a chart and edit it to have no decimals on the y axis ticks.  Then use File > Save Chart Template in the Chart Editor and select only that one property to save.  After that, when you want this property, just included that template in the specification.

    GPL is mainly concerned with chart structure and data.  Many of the display properties of a chart cannot be specified that way, but the chart templates provide that capability.

    --





  • 9.  RE: Axis labels on graph

    Posted Tue September 17, 2024 01:48 PM

    Thanks for all the suggestions.

    I found a GPL-centric way to get the result I wanted.

    GGRAPH 
      /GRAPHDATASET NAME="graphdataset" VARIABLES=ypll_75 COUNT()[name="count"] 
      /GRAPHSPEC SOURCE=INLINE. 
    BEGIN GPL 
    SOURCE: s=userSource(id("graphdataset")) 
    DATA: ypll_75=col(source(s), name("ypll_75"), unit.category()) 
    DATA: count=col(source(s), name("count")) 
    GUIDE: text.title(label("Frequency of Years of potential life lost - 2019-2021: Hispanic/Latino")) 
    GUIDE: axis(dim(1), label("Years of potential life lost")) 
    GUIDE: axis(dim(2), label("# of deaths")) 
    SCALE: linear(dim(2), include(0)) 
    ELEMENT: interval(position(ypll_75*count), shape.interior(shape.square)) 
    END GPL.

    This seems to work.

    Thanks again.



    ------------------------------
    Urban Landreman
    ------------------------------