Book Image

R Data Visualization Cookbook

Book Image

R Data Visualization Cookbook

Overview of this book

Table of Contents (17 chapters)
R Data Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Connecting points in a scatter plot


The primary objective of this recipe is to understand how we can connect points in a scatter plot. The plot is inspired by Alberto Cairo infographic regarding the Gini coefficient, and the GDP data under various president's tenure in Brazil and connected points based on these three variables. In this recipe, we will apply the same concept to the USA economy.

Tip

For all the data visualizations and references used in recipes in this book, please refer to the See also section in each recipe

How to do it…

We will start to import the data in R. The dataset comprises of the Gini coefficient, the GDP data of the USA and USA presidents. The Gini coefficient is used as a measure of inequality in a country:

data = read.csv("ginivsgdp1.csv", header = TRUE)

The plot can be generated using the plot() function:

plot(income$gdp_ann,income$Gini,pch = 20, col = c(data$Presidents), type = "o",xlab =" GDP of USA", ylab = "Gini coefficient",main = "Inequality in USA", xaxp = c...