Asjad Naqvi Profile picture
Oct 15, 2022 13 tweets 8 min read Read on X
A late night 🧵 on some tips for making grayscale (BW) & colorblind (cblind) friendly graphs in @Stata. BW in case people print out papers, and cblind to make sure documents are "barrier free".

Graphs have 3 elements that we can control: colors, line patterns, & symbols.

1/
Let's start with colors: Whatever color scheme we use, we can check whether it will pass the BW and cblind tests. This can be easily tested using the palettes package. Install these, if you haven't already:

ssc install palettes, replace
ssc install colrspace, replace

2/
There are three types of common color-blindnesses that can we can check in #Stata: "Protanopia" & "Deuteranopia" where shades of red and green are not discernable, & "Tritanopia" where blue-green, purple-red, yellow-pink are hard to differentiate.

Test yourself 👇👇

3/ Image
The extreme case is where one has both red-green & blue-yellow colorblindness.

Let's take the default s2 colors & see if it passes the test: The BW part has gray shades spaced out for the first 5 colors but spacing is not even. Same for cblind.

4/ ImageImage
There are several well thought-out color palettes readily available. For example, I use "tableau" a lot. Let, see how it does using the same code as above but just replacing s2 with tableau:

It sort of also works for grayscale and some of the cblind options but not all.

5/ Image
Let's try 2 purpose built schemes: These are "okabe" and "viridis". Okabe is for discrete variables. You can see that it passes the cblind test very well but not the B&W one. But look at Viridis. You can see immediately what makes it so popular. It passes all the tests 🤩!

6/ ImageImage
Below r the results of the 4 cblind schemes I have released as part of the schemepack (github.com/asjadnaqvi/Sta…)

tab1, tab2, tab3, cblind1

They all work well for colorblindness, maybe not for all BW shades. Here we can add additional elements for more control.

7/ ImageImageImageImage
These are markers and lines. By default I do not build these inside my own schemes. They are controlled at a second stage. Let's see how:

Load the schemepack, data, and do a basic plot. Tableau colors are great for colored images but maybe they do not work well in BW.

8/ ImageImage
Let's pass a cblind friendly color scheme. Here Okabe gives us higher contrast in colors.

We can also select any other cblind scheme from the "colorpalettes" package and pass it.

For more info, check this guide:
medium.com/the-stata-guid…

9/ ImageImage
We can also pass on custom line patterns using "linepalette" (also part of the palettes suite), where we can access sets of different patterns.

The command also allows us to pick the patterns we want using the "select" option. See its help file.

10/ ImageImage
Lastly, we can also customize the markers using the "symbolpalette". We can also pick & choose sets & select markers within them.

We can also combine all of the above 3 elements. Just need some pratice with storing & passing around locals. But this should be case-dependant!

11/ ImageImage
To summarize: colors, line patterns, & markers can be easily modified in #Stata to create BW & cblind friendly graphs. It might seem a lot of work, but one can generate a template of colors & patterns and save these, either in custom scheme files, or just as scripts.

12/
I have a guide on generating scheme files here:
medium.com/the-stata-guid…

You can also use "grstyle" or "brewscheme" packages, or generate .style files (advanced application!) to create customized graphs on the fly.

Make this one-time investment and up your graph game!

/END

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Asjad Naqvi

Asjad Naqvi Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @AsjadNaqvi

Sep 13, 2023
#Stata v18 has added a bunch of new features to control colors in the past updates. Let's start with an example data:

set scheme stcolor
sysuse census.dta, clear
gen under5 = (poplt5 / pop) * 100

twoway (scatter under5 medage, msize(2))

The scheme layout has minor tweaks: Image
A new feature of v18 is to color by groups using a single line:

twoway (scatter under5 medage, msize(2) colorvar(region) colordiscrete)

This is amazing but 2 issues; discrete variables should have a regular legend. The line legend is confusing. The hues are not readable. Image
More options have been added to define start and end colors

twoway (scatter under5 medage, msize(2) colorvar(region) colordiscrete colorstart(red) colorend(eltblue))

But still we end up with hues where categories 3 and 4 are not discernible. Image
Read 9 tweets
Oct 31, 2022
The #30DayMapChallenge 2022 starts tomorrow. In the last 2 years a lot of work has been put in @Stata to mainstream some of the map elements we find in other softwares. He is a 🧵 on the different types of maps one can make. If you want the code for any, just msg! Let's go 👇
The basic #spmap package can already do a lot! Here are some examples using standard spmap syntax.

These were made for the online #GIS tutorials earlier this year that were fairly well attended! Over 1400+ registrations and 500+ ppl online. Might repeat it again. ImageImageImageImage
The #bimap package that actually was the result of the #30DayMapChallenge last year allows you to combine two variables to check for interesting spatial correlations.

Install from SSC (ssc install bimap, replace)

See GitHub for further instructions
github.com/asjadnaqvi/sta… ImageImageImageImage
Read 11 tweets
Oct 28, 2022
Half through sorting the #dataviz bookmarks and still haven't found the links I am looking for (the curse of over bookmarking).

But here are 10+1 super amazing, interactive, and midn-blowing🤯 #environment, #climate, #trade, #emissions related websites that are just 🤩

👇👇
1/ The #WorldBank's #SDG atlas covers each #SDG goal in detail with some great datavizzes inside each of them. Check it out! Really a lot of effort went into this.

datatopics.worldbank.org/sdgatlas/
2/ @ChathamHouse brings an interactive resource website that allows you to explore bi-lateral #trade linkages. Data currently ranges from 2000-2020.

resourcetrade.earth
Read 13 tweets
Oct 11, 2022
The ultimate clustering standard errors paper just dropped:

When Should You Adjust Standard Errors for Clustering?

by some big names in the field :)

academic.oup.com/qje/advance-ar…
Here is a quick paper pass: The authors discuss 3 misconceptions:

1) clustering is needed when smaller units are correlated with larger units (its not!)

2) just do clustering for the sake of robustness (dont!)

3) researchers use either cluster SEs OR robust SEs (use both!)
The authors provide a discussion and recommendations on:

1) clustering strategy in the design process (e.g. sampling, DGP etc.)

2) clustering strategy in the assignment process (e.g. clustering of treatments etc.)

Second can also help understand the data better.
Read 5 tweets
Sep 14, 2022
A 🧵 to consolidate the #Statatip posts from the past three years! Bookmark these.

If you want to read them in detail, have a look at the Awesome @Stata tips collection:

medium.com/the-stata-guid…

Its updated every 2-3 months or so. Many tips below 👇
Read 38 tweets
Sep 9, 2022
A 🧵 to keep track of my @Stata #dataviz packages 👇

1) 𝘀𝗰𝗵𝗲𝗺𝗲𝗽𝗮𝗰𝗸: Has a large collection of ready-to-use #Stata #schemes.

Two I personally use all the time are white_tableau (clean white) and neon (black background).

github.com/asjadnaqvi/Sta…
2) 𝗷𝗼𝘆𝗽𝗹𝗼𝘁: A #Stata package for classic #ridgeline plots

github.com/asjadnaqvi/sta…
3) 𝘀𝘁𝗿𝗲𝗮𝗺𝗽𝗹𝗼𝘁: A #Stata package for centered area graphs

github.com/asjadnaqvi/sta…
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(