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...