Skip to main content
added 42 characters in body
Source Link
library(dplyr) # for data manipulation library(tidyr) # for reshaping the data frame library(stringr) # string manipulation library(ggplot2) # graphing # create the data frame # (in wide format, as needed for the line segments): dat_wide = tibble::tribble( ~Country, ~Y1990, ~Y2015, 'Russia', 71.5, 101.4, 'Canada', 74.4, 102.9, 'Other non-OECD Europe/Eurasia', 60.9, 135.2, 'South Korea', 127, 136.2, 'China', 58.5, 137.1, 'Middle East', 170.9, 158.8, 'United States', 106.8, 169, 'Australia/New Zealand', 123.6, 170.9, 'Brazil', 208.5, 199.8, 'Japan', 181, 216.7, 'Africa', 185.4, 222, 'Other non-OECD Asia', 202.7, 236, 'OECD Europe', 173.8, 239.9, 'Other non-OECD Americas', 193.1, 242.3, 'India', 173.8, 260.6, 'Mexico/Chile', 221.1, 269.8 ) # a version reshaped to long format (for the points): dat_long = dat_wide %>% gather(key = 'Year', value = 'Energy_productivity', Y1990:Y2015) %>% mutate(Year = str_replace(Year, 'Y', '')) # create the graph: ggplot() + geom_segment(data = dat_wide, aes(x = Y1990, xend = Y2015, y = reorder(Country, Y2015), yend = reorder(Country, Y2015)), size = 3, colour = 'darkgrey''#D0D0D0') + geom_point(data = dat_long, aes(x = Energy_productivity, y = Country, colour = Year), size = 4) + labs(title = 'Energy productivity in selected countries \nand regions', subtitle = 'Billion dollars GDP per quadrillion BTU', caption = 'Source: EIA, 2016', x = NULL, y = NULL) + scale_colour_manual(values = c('#1082CD', '#042B41')) + theme_bw() + theme(legend.position = c(0.8592, 0.1520), legend.title = element_blank(), legend.box.background = element_rect(colour = 'black'), panel.border = element_blank(), axis.ticks = element_line(colour = '#E6E6E6')) ggsave('energy.png', width = 20, height = 10, units = 'cm') 
library(dplyr) # for data manipulation library(tidyr) # for reshaping the data frame library(stringr) # string manipulation library(ggplot2) # graphing # create the data frame # (in wide format, as needed for the line segments): dat_wide = tibble::tribble( ~Country, ~Y1990, ~Y2015, 'Russia', 71.5, 101.4, 'Canada', 74.4, 102.9, 'Other non-OECD Europe/Eurasia', 60.9, 135.2, 'South Korea', 127, 136.2, 'China', 58.5, 137.1, 'Middle East', 170.9, 158.8, 'United States', 106.8, 169, 'Australia/New Zealand', 123.6, 170.9, 'Brazil', 208.5, 199.8, 'Japan', 181, 216.7, 'Africa', 185.4, 222, 'Other non-OECD Asia', 202.7, 236, 'OECD Europe', 173.8, 239.9, 'Other non-OECD Americas', 193.1, 242.3, 'India', 173.8, 260.6, 'Mexico/Chile', 221.1, 269.8 ) # a version reshaped to long format (for the points): dat_long = dat_wide %>% gather(key = 'Year', value = 'Energy_productivity', Y1990:Y2015) %>% mutate(Year = str_replace(Year, 'Y', '')) # create the graph: ggplot() + geom_segment(data = dat_wide, aes(x = Y1990, xend = Y2015, y = reorder(Country, Y2015), yend = reorder(Country, Y2015)), size = 3, colour = 'darkgrey') + geom_point(data = dat_long, aes(x = Energy_productivity, y = Country, colour = Year), size = 4) + labs(title = 'Energy productivity in selected countries \nand regions', subtitle = 'Billion dollars GDP per quadrillion BTU', x = NULL, y = NULL) + scale_colour_manual(values = c('#1082CD', '#042B41')) + theme_bw() + theme(legend.position = c(0.85, 0.15), legend.title = element_blank(), legend.box.background = element_rect(colour = 'black'), panel.border = element_blank(), axis.ticks = element_line(colour = '#E6E6E6')) ggsave('energy.png', width = 20, height = 10, units = 'cm') 
library(dplyr) # for data manipulation library(tidyr) # for reshaping the data frame library(stringr) # string manipulation library(ggplot2) # graphing # create the data frame # (in wide format, as needed for the line segments): dat_wide = tibble::tribble( ~Country, ~Y1990, ~Y2015, 'Russia', 71.5, 101.4, 'Canada', 74.4, 102.9, 'Other non-OECD Europe/Eurasia', 60.9, 135.2, 'South Korea', 127, 136.2, 'China', 58.5, 137.1, 'Middle East', 170.9, 158.8, 'United States', 106.8, 169, 'Australia/New Zealand', 123.6, 170.9, 'Brazil', 208.5, 199.8, 'Japan', 181, 216.7, 'Africa', 185.4, 222, 'Other non-OECD Asia', 202.7, 236, 'OECD Europe', 173.8, 239.9, 'Other non-OECD Americas', 193.1, 242.3, 'India', 173.8, 260.6, 'Mexico/Chile', 221.1, 269.8 ) # a version reshaped to long format (for the points): dat_long = dat_wide %>% gather(key = 'Year', value = 'Energy_productivity', Y1990:Y2015) %>% mutate(Year = str_replace(Year, 'Y', '')) # create the graph: ggplot() + geom_segment(data = dat_wide, aes(x = Y1990, xend = Y2015, y = reorder(Country, Y2015), yend = reorder(Country, Y2015)), size = 3, colour = '#D0D0D0') + geom_point(data = dat_long, aes(x = Energy_productivity, y = Country, colour = Year), size = 4) + labs(title = 'Energy productivity in selected countries \nand regions', subtitle = 'Billion dollars GDP per quadrillion BTU', caption = 'Source: EIA, 2016', x = NULL, y = NULL) + scale_colour_manual(values = c('#1082CD', '#042B41')) + theme_bw() + theme(legend.position = c(0.92, 0.20), legend.title = element_blank(), legend.box.background = element_rect(colour = 'black'), panel.border = element_blank(), axis.ticks = element_line(colour = '#E6E6E6')) ggsave('energy.png', width = 20, height = 10, units = 'cm') 
Source Link

The answer by @gung is correct in identifying the chart type and providing a link to how to implement in Excel, as requested by the OP. But for others wanting to know how to do this in R/tidyverse/ggplot, below is complete code:

library(dplyr) # for data manipulation library(tidyr) # for reshaping the data frame library(stringr) # string manipulation library(ggplot2) # graphing # create the data frame # (in wide format, as needed for the line segments): dat_wide = tibble::tribble( ~Country, ~Y1990, ~Y2015, 'Russia', 71.5, 101.4, 'Canada', 74.4, 102.9, 'Other non-OECD Europe/Eurasia', 60.9, 135.2, 'South Korea', 127, 136.2, 'China', 58.5, 137.1, 'Middle East', 170.9, 158.8, 'United States', 106.8, 169, 'Australia/New Zealand', 123.6, 170.9, 'Brazil', 208.5, 199.8, 'Japan', 181, 216.7, 'Africa', 185.4, 222, 'Other non-OECD Asia', 202.7, 236, 'OECD Europe', 173.8, 239.9, 'Other non-OECD Americas', 193.1, 242.3, 'India', 173.8, 260.6, 'Mexico/Chile', 221.1, 269.8 ) # a version reshaped to long format (for the points): dat_long = dat_wide %>% gather(key = 'Year', value = 'Energy_productivity', Y1990:Y2015) %>% mutate(Year = str_replace(Year, 'Y', '')) # create the graph: ggplot() + geom_segment(data = dat_wide, aes(x = Y1990, xend = Y2015, y = reorder(Country, Y2015), yend = reorder(Country, Y2015)), size = 3, colour = 'darkgrey') + geom_point(data = dat_long, aes(x = Energy_productivity, y = Country, colour = Year), size = 4) + labs(title = 'Energy productivity in selected countries \nand regions', subtitle = 'Billion dollars GDP per quadrillion BTU', x = NULL, y = NULL) + scale_colour_manual(values = c('#1082CD', '#042B41')) + theme_bw() + theme(legend.position = c(0.85, 0.15), legend.title = element_blank(), legend.box.background = element_rect(colour = 'black'), panel.border = element_blank(), axis.ticks = element_line(colour = '#E6E6E6')) ggsave('energy.png', width = 20, height = 10, units = 'cm') 

Graph as implemented in ggplot

This could be extended to add value labels and to highlight the colour of the one case where the values swap order, as in the original.