Announcement

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

  • Color graphs changed into black-and-white display

    Dear Statalisters,

    I have a series of color graphs I did in Stata and saved as *.gph. However, the Journal I chose to send the paper demands only black-and-white graphs. The problem is: there will be need to change many aspects of the graphs so as to make them fully "understandable" in black-and-white: lines, markers, legends, etc. All graphics were performed after - marginsplot - , and two of them were combined into a single graph.

    I know I could start from scratch, perform the estimations and choose the option - scheme - to monocrome, but I wonder if there it's a shortcut to change them into black-and-white and at the same time allow automatic modifications related to the above-mentioned aspects.

    Kind regards

    Marcos
    Last edited by Marcos Almeida; 29 Mar 2015, 09:58.
    Best regards,

    Marcos

  • #2
    First create a local macro with the names of the graphs you want to convert to black and white. Let's call it to_convert.

    Code:
    foreach t of local to_convert {
        graph use `"`t'"', scheme(s2mono)
        graph save `"`t'_bw"'
    }
    I believe this will work no matter how the graphs were originally created, as long as they were saved as .gph files.

    And this should also work with any of the other monochrome schemes, not just s2mono.


    Comment


    • #3
      Thank you so much for the prompt answer, Clyde.

      I choose one graphic, tried the commands,got no error message, but the graph didn't change. I opened the graph first, and used this directory as the working directory. I don't know what may have happened. By the way, I typed the name of the graph (groupdiabetes) with and without the ".gph" extension, always without quotation marks, unfortunately of no avail. I wonder if you know what might have happened...

      Best,

      Marcos
      Best regards,

      Marcos

      Comment


      • #4
        Strange, because I tested that code before posting it. And it did save all of the graphs I tried it on in black and white--and I was able to then -use- those graphs and they opened in black and white. I don't know what to say.

        Just to be clear, the code I posted leaves the original graphs unchanged in storage. It creates modified versions saved with names followed by _bw. If I re-open the original graphs, they are still in color. But when I open the *_bw.gph graphs the code created, they are in black and white.
        Last edited by Clyde Schechter; 29 Mar 2015, 13:48.

        Comment


        • #5
          Now I got it, Clyde! I had the old graph opened, therefore I still saw the old display. Thank you very much for your very helpful suggestion!

          Best,

          Marcos
          Best regards,

          Marcos

          Comment


          • #6
            Hi! I think I might be a little more new to Stata and I also want to switch to a black and white scheme but I don't think I'm as advanced as Mr. Almeida. I didn't know how to use a local macro but I use global macros so I think I get the concept. This is the code that I added to the beginning of my document:
            Code:
            local bw "/Users/Jflamross/Dropbox/May_2018_Research/graphs/"
            Is this correct?
            And then I saved my graph:
            Code:
            graph save "$local/graph1", replace
            But I'm hitting an error when I try to run this line. The error says "file /graph1.gph could not be opened" so I can't even get to the part where I run the code you gave! Do you know what the problem might be? As far as troubleshooting, I went back to make sure I entered the location where it's saved correctly and I also closed the log file and tried running the "local bw..." line both before and after starting a new log file. Thank you!

            Comment


            • #7
              Hi guys - and especially Clyde and Marcos!

              Originally posted by Clyde Schechter View Post
              First create a local macro with the names of the graphs you want to convert to black and white. Let's call it to_convert.

              Code:
              foreach t of local to_convert {
              graph use `"`t'"', scheme(s2mono)
              graph save `"`t'_bw"'
              }
              I believe this will work no matter how the graphs were originally created, as long as they were saved as .gph files.

              And this should also work with any of the other monochrome schemes, not just s2mono.
              I guess, I can't manage to create the local the right way. How is it supposed? Like
              Code:
              local conv2bw "name1.gph name2.gph name*.gph"
              ?
              And, should I use something instead of the t in the code posted above? What does this t stand for?
              Code:
              foreach c of local conv2bw {
              graph use `"`c'"', scheme(s2mono) graph save `"`c'_bw"', replace
              }

              Thanks a lot!!
              Last edited by Franz Gerbig; 26 Jul 2018, 08:10.
              Thank you for reading (and some reply)
              Using Stata 16.1
              Extractions (-dataex-) of the data I'm working with is impossible, sorry!

              Comment


              • #8
                Your local macro conv2bw will not work as you intend: the * wildcard will not be understood when it is reached in your loop. Also, omit the .gph filename extensions, so your final graphs don't have names like name1.gph_bw. You can do it like this:

                Code:
                local conv2bw name1 name2 name3 // KEEP GOING AND LIST THEM ALL
                foreach c of local conv2bw {
                    graph use `"`c'"', scheme(s2mono)
                    graph save `"`c'_b2"', replace
                }
                If the number of graphs involved makes it impractical to write out all their names to define local macro conv2bw, but if the list can be condensed using a wildcard, then you can define the local macro this way:

                Code:
                local conv2bw: dir "." files "*.gph"
                local conv2bw: subinstr local conv2bw ".gph" "", all
                That will place a list of all the .gph files in the current directory into your local macro. You can replace "." with whatever directory the graphs are actually in if it isn't the current one. And you can replace "*.gph" with some other wildcard expression that correctly selects the particular graphs you want if it isn't every .gph file in the directory.

                Comment


                • #9
                  Hi Clyde,

                  you're such a good guy - even answering the next question not even asked, yet (concerning the reference to a whole dir instead of specific files) !-)
                  Thanks a lot!!!

                  Notwithstanding, it doesn't work the easiest way (see below), but a lot more efficient than converting every single .gph! (Sorry for code in an image - I'm working in a terminal session I'm not able to copy out of (only make snapshots like this.)
                  Click image for larger version

Name:	scheme.JPG
Views:	1
Size:	56.0 KB
ID:	1455251

                  Last edited by Franz Gerbig; 27 Jul 2018, 03:41.
                  Thank you for reading (and some reply)
                  Using Stata 16.1
                  Extractions (-dataex-) of the data I'm working with is impossible, sorry!

                  Comment


                  • #10
                    Hi,

                    Sorry for adding to an older post, but can this method be used with png files as well or only gph files? I will be grateful for your help.
                    Sincerely,
                    Sumedha.

                    Comment

                    Working...
                    X