Select Page


It seems like all of the sudden, everyone is talking about artificial intelligence.

Up until about 8 months ago, if I mentioned in a conversation that robotics and artificial intelligence would re-shape the economy, people would look at me with that distant, vacant look that signals that they have no f#!^ing idea what I’m talking about.

But all of the sudden, everyone is talking about AI.

When your cab driver is telling you about “machine learning,” you know that something has changed.

And while it definitely feels like we’re at some inflection point, I think this is just the beginning.

As I wrote about quite some time ago, we are now entering a new era … an era defined by artificial intelligence. As noted by the famous machine learning expert Andrew Ng, just like electricity transformed the world 100 years ago, artificial intelligence will transform the economy now. Other public intellectuals have made similar statements, like Kevin Kelly suggesting that we’re going to add little bits of intelligence to just about everything.

Even right now, companies like Google are reshaping their entire business strategy around AI and machine learning.

What will this mean for the world economy?

Although I’m always skeptical about forecasting, there are smart people who have thought about this and have made some projections.

Recently, I read a report by pwc that suggested that artificial intelligence will add an additional $15 trillion to the world economy by 2030. That’s on top of any economic growth that would have happened.

To put that in context, that’s almost as large as the entire economy of the USA (the US economy is at about $18 trillion in 2017).

The pwc report actually broke their numbers out by region; they created projections of added economic growth for North America, China, Europe, etc.

When I saw these numbers, I thought that they would make for a good, small dataset that you (dear blog reader) could use to practice your visualization skills.

Code: plotting projected economic growth

Here, we’re going to use pwc’s numbers and make a bar chart.

You can find the original data in figure 2 on page 7 of the pwc analysis.

They originally visualized this data as a map-based infographic. Although there is a geo-spatial component to the regional data, I don’t think that the infographic they created was the best choice. In this case, I actually think that the humble bar chart is better, simply because bar charts enable you to make more accurate and precise comparisons.

So, let’s re-work this into a bar chart.

First, let’s just load the packages that we’ll need. We’ll actually be working primarily with ggplot2, but we can just load tidyverse. tidyverse will load ggplot2 along with several other important packages (just in case).


Next, we’ll create a data frame that we can work with.

Because the data are not in a format that we can read in (like a .csv or text file), we’ll need to hand code this. To do this, we will use the tribble() function.

Although entering data manually using tribble() can be very time consuming for large datasets, here we’ll be working with only a few data points, so it doesn’t take much effort.

Essentially, tribble() will create a tibble (i.e., a modified data frame), and it works by allowing you to hard-code the data by hand in a row-by-row format.

# In this post, we will be using data from an analysis
# performed by pwc
# source:

df.ai_growth <- tribble(
                  ~region, ~ai_econ_growth
                  ,"China", 7
                  ,"North America", 3.7
                  ,"Northern Europe", 1.8
                  ,"Africa, Oceania, & Other Asia", 1.2
                  ,"Developed Asia", .9
                  ,"Southern Europe", .7
                  ,"Latin America", .5

Next, let’s just create a first draft. We’ll create a simple bar chart with essentially no formatting. By making this “rough draft” plot first, we are essentially using the strategy of building plots iteratively.

# (bar chart)

ggplot(data = df.ai_growth, aes(x = region, y = ai_econ_growth)) +
  geom_bar(stat = 'identity')

This bar chart is a little hard to read in it’s native form, because the category labels on the x-axis overlap.

To mitigate this problem, we’re going to flip the chart on its side and create a horizontal bar chart by using coord_flip().

One quick note: I frequently prefer these when we have long text names for the bar categories. They are simply much easier to read.

ggplot(data = df.ai_growth, aes(x = region, y = ai_econ_growth)) +
  geom_bar(stat = 'identity') +

This looks better, but there’s now a new issue: the bars are arranged in alphabetical order, which looks odd.

To fix this, we need to reorder the bars in order of bar length.

To accomplish this, we’ll use fct_reorder() from the forcats package.

# - reorder by econ growth
#   using forcats::fct_reorder()

ggplot(data = df.ai_growth, aes(x = fct_reorder(region, ai_econ_growth), y = ai_econ_growth)) +
  geom_bar(stat = 'identity') +

Ok, this looks much better.

If you had no intention of sharing this visualization or presenting it in a formal setting, you might just stop here. Typically, if you only need to use a chart personally, or only intend to share it with immediate team members (and not in some sort of formal document or presentation), most of the ggplot2 defaults are good enough. In that case, you want to modify the chart enough so that it’s easy to understand, but no more.

Having said that, if the chart will be used in a publication or an important presentation (e.g., you are creating a PowerPoint presentation that will be shown to important clients, executives, investors, etc.) you will want to make your charts look more “polished.”

If that’s the case, you’ll need to format them.

Here, we’re going to use the ggplot2 theme system to create a theme that we can apply that will format the chart.

Explaining exactly how this works is beyond the scope of this post. I also won’t explain good design here …. but eventually, you need to understand design principles to make great visualizations. And you need to learn the ggplot2 theme system backwards-and-forwards to be able to format your plots easily.


theme.futurae <- theme(text = element_text(family = 'Gill Sans', color = "#444444")
                       ,panel.background = element_rect(fill = '#444B5A')
                       ,panel.grid.minor = element_line(color = '#4d5566')
                       ,panel.grid.major = element_line(color = '#586174')
                       ,plot.title = element_text(size = 26)
                       ,axis.title = element_text(size = 18, color = '#555555')
                       ,axis.title.y = element_text(vjust = .7, angle = 0)
                       ,axis.title.x = element_text(hjust = .5)
                       ,axis.text = element_text(size = 12)
                       ,plot.subtitle = element_text(size = 14)

Ok, now that we have our theme, we’ll apply it to create our finalized plot.


ggplot(data = df.ai_growth, aes(x = fct_reorder(region, ai_econ_growth), y = ai_econ_growth)) +
  geom_bar(stat = 'identity', fill = 'cyan') +
  coord_flip() +
  labs(x = NULL
       , y = 'Projected AI-driven growth (Trillion USD)'
       , title = 'AI is projected to add an additional\n$15 Trillion to the global economy by 2030'
       , subtitle = '...strongest growth predicted in China & North America') +
  annotate(geom = 'text', label = "source:", x = 1, y = 6, color = 'white') +

Here is the final chart:


A couple of quick notes:

First, notice that it is much easier to make direct comparisons when we use a bar chart. I won’t explain why in detail, but essentially, the human brain is wired to make accurate comparisons of length. Humans are good at comparing lengths (and not as good at comparing abstract numbers, or areas, or shade gradients, etc). Because of this, the simple bar chart is often the best choice when you need to compare numbers across categories.

Second, speaking about the content of this projection itself: I am a little skeptical of these exact regional projections. I’m not at all convinced that China will get more benefit from AI developments than the US or the rest of “developed Asia” (which presumably includes Japan, Taiwan, etc). So, don’t mistake the fact that I’ve created this chart for a ringing endorsement of pwc’s numbers.

More than anything, I think the AI boom is interesting, and I that this gives you a small, well-contained dataset that you can use to learn and practice your visualization technique.

If you want to get started with AI, you need to master the basics

Even if I am skeptical of pwc’s exact projections, I absolutely think that AI will effect almost every part of our economy. Just like electricity “changed everything” 100 years ago, AI will change everything over the next few decades.

That said, you need to strongly consider mastering AI and machine learning. It’s a tremendously exciting time, and if these projections of an added $15 trillion are even remotely close, fortunes will be made.

Sign up now, and discover how to master machine learning

Machine learning will be worth trillions of dollars over the next few decades.

… mastering machine learning is really, really hard, but it doesn’t have to be.

Sign up now and discover how to rapidly master the tools of ML and data science.

When you sign up, you’ll get machine learning and data science tutorials (delivered regularly to your inbox) …

And you’ll also get access to our “Data Science Crash Course” for free.