Announcement

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

  • Fixed bar-width in bargraph

    Hi Statalist,

    I am trying to make six bar charts summarizing data from a review. Some of the graphs have many bars and some have fewer, but I would like all the graphs to look similar by giving them the same bar-width. However, as I understand it is not possible to set bar-width using the graph hbar command. I have tried to change the size of the graph window, which helps a bit, but not completely.

    The first graph is created like this:

    graph hbar AAbw, ///
    over (MeanP501) bar(1, color(black)) bar(2, color(gs8)) ///
    over(study, label(labsize(tiny))) ///
    over(country, label(labsize(vsmall)) gap(400)) nofill ///
    ytitle("Acrylamide (μg/kg bw/day)", size(vsmall)) ///
    ysize(8) ///
    xsize(5) ///
    ylabel(0(0.1)0.9, labsize(vsmall)) ///
    legend(size(vsmall)) ///
    graphregion(color(white))

    And looks like this

    Click image for larger version

Name:	Figure 2.png
Views:	1
Size:	68.1 KB
ID:	1614736


    While another graph is created like this:

    graph hbar AAday, ///
    over (MeanP502) bar(1, color(black)) bar(2, color(gs8)) ///
    over(study, label(labsize(tiny))) ///
    over(country, label(labsize(vsmall)) gap(400)) nofill ///
    ytitle("Acrylamide (μg/day)", size(vsmall)) ///
    ysize(5) ///
    xsize(5) ///
    ylabel(0(5)30, labsize(vsmall)) ///
    legend(size(vsmall)) ///
    graphregion(color(white))

    And looks like this:

    Click image for larger version

Name:	Figure 5.png
Views:	1
Size:	43.3 KB
ID:	1614737


    I have tried to make the bars in the second graph thinner by reducing the height of the graph:

    graph hbar AAday, ///
    over (MeanP502) bar(1, color(black)) bar(2, color(gs8)) ///
    over(study, label(labsize(tiny))) ///
    over(country, label(labsize(vsmall)) gap(400)) nofill ///
    ytitle("Acrylamide (μg/day)", size(vsmall)) ///
    ysize(3) ///
    xsize(5) ///
    ylabel(0(5)30, labsize(vsmall)) ///
    legend(size(vsmall)) ///
    graphregion(color(white))


    But that just makes the space used for the y-axis text smaller (and preferably I would like that space to be similar in all the graphs):

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	45.5 KB
ID:	1614738


    Is there any way for me to control the bar-width in these graphs?

    Thank you in advance,
    Amalie

  • #2
    See if the following (#13) is helpful.

    https://www.statalist.org/forums/for...nal-formatting

    Comment


    • #3
      Dear Andrew,

      Thank you very much for your fast reply! Increasing the gap between the bars does help reducing the bar width.
      However, I does leave me with a lot of empty space in my graph.
      Click image for larger version

Name:	Figure 5.png
Views:	1
Size:	43.1 KB
ID:	1614749

      Do you know if there is any way to reduce the height of the graph (as in the third graph in my first post) without decreasing the space allocated for the y-axis text?

      Also, when I save the graphs to my computer, the quality of the highest graphs is not so good (hard to read the tiny text), whereas the quality of the smaller graphs is ok (I tried saving as png, tiff and highest quality jpeg - it is the same for all formats). Do you know if there is any way to create the high graph in a way that will allow higher quality when exported?

      Best regards,
      Amalie

      Comment


      • #4
        If you want consistency, you should attempt to use the by() option. See, e.g., https://journals.sagepub.com/doi/pdf/10.1177/1536867X20976341t. That said, provide a data example using dataex that can allow some experimentation.

        Do you know if there is any way to create the high graph in a way that will allow higher quality when exported?
        You can increase the image quality by specifying the -width- and -height- options (these are in pixels), e.g.,

        Code:
        graph export mygraph.png, width(2600) height(1720)

        Comment


        • #5
          Perfect. Be adjusting the resolution differently for the height and the width, I was also able to adjust the width of the bars. Thank you very much!

          Comment

          Working...
          X