Announcement

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

  • Adding logos to graphs created in Stata

    Hi, I use Stata SE 19.5 for Windows 11 Pro. I do a lot of simple data analysis, supported by graphs of data (scatters, time series, histograms, etc.) I would like to add logos to some of my graphs as I create them but have struggled to do so in a scale-able way. For one graph, it's OK to use Paint or something to do that. For example, I used Stata to create this graph of monthly sales, and then I manually added a logo in the upper left hand corner. How might I use Stata commands to do this so I can "automate" the logo addition in some way? Would welcome suggestions. Thank-you!

    Click image for larger version

Name:	monthly_retail_sales.png
Views:	2
Size:	243.2 KB
ID:	1786796

    Click image for larger version

Name:	monthly_retail_sales_with_logo.png
Views:	1
Size:	297.8 KB
ID:	1786795
    Attached Files

  • #2
    I do this frequently and my current workflow of this sort uses Python integration in modern Stata (via some combination of ImageMagick, Pillow, and SVG rasterizers in python).
    I dont have a one-size-fits-all solution but this workflow on my github has been serviceable for me, you can install and try out the example do files I dropped there. It will overlay small logos on stata graphs in most cases.

    The syntax of this implementation looks like this pseudo-example:

    Code:
    sysuse auto, clear
    twoway (scatter price mpg, mcolor(navy%60))                    ///
           (lfit price mpg, lcolor(cranberry) lwidth(medthick)),   ///
           title("Price vs. mileage")                              ///
           name(g1, replace)
    addlogo, logo("testlogo.png") ///
        saving("example.png") ///
        name(g1) position(nw) scale(.18) opacity(.85) replace
    Install via github here (has some test examples and files to run): https://github.com/ericabooth/addlogo-stata-public

    To install:
    Code:
    net install addlogo, from("https://raw.githubusercontent.com/ericabooth/addlogo-stata-public/main/") replace force
    help addlogo




    PS: Alternative outside-the-box suggestion: make your own font file (LLMs can help make these files) and add your logo by this method: https://techtips.surveydesign.com.au...aphic-in-stata
    There exist some older threads on this where I suggested some hackish solutions, but I think the approach above now that Stata has Python is cleaner (see: https://www.statalist.org/forums/for...in-stata-graph) Finally, I find this presentation by Sergiy Radyakin inspirational for this kind of work (see the mention of ppm files at the end) https://www.stata.com/meeting/dcconf...9_radyakin.pdf
    Eric A. Booth | Sr. Researcher | Texas2036.org | www.github.com/EricABooth

    Comment


    • #3
      Thanks for these great suggestions. I will explore.

      Comment


      • #4
        Originally posted by Paula Worthington View Post
        Thanks for these great suggestions. I will explore.
        Update: I have a version working now. Considering that I have never touched Python before and had to install it to get going here, I am pleased! Thank-you again!

        Comment

        Working...
        X