Scatter Plot: Inequality

<< Click to Display Table of Contents >>

Navigation:  Resources > R Code samples >

Scatter Plot: Inequality

The code shown below was used to create the scatter plot example in the Graphics and Visualization section. The full set of countries is included but note that two entries (Israel and Singapore) are incomplete, and R ignores these in this case.

R Code

## read csv formatted file (as per the dataset shown below)

data<-read.table("d:\\statsref\\inequality.csv",header=T,sep=",")

attach(data)

## generate x,y scatterplot

plot(Income_inequality,Index)

## add labels

text(Income_inequality,Index,labels=Country,pos=3,offset=0.5,cex=0.7)

## add regression line from linear model lm() and provide summary stats

regr<-lm(Index~Income_inequality)

abline(regr)

summary(regr)

Dataset

Country,Income_inequality,Index

Australia,7.00,0.07

Austria,4.82,0.01

Belgium,4.60,-0.23

Canada,5.63,-0.07

Denmark,4.30,-0.19

Finland,3.72,-0.43

France,5.60,0.05

Germany,5.20,-0.06

Greece,6.20,0.38

Ireland,6.05,0.25

Israel,6.78,

Italy,6.65,-0.12

Japan,3.40,-1.26

Netherlands,5.30,-0.51

New Zealand,6.80,0.29

Norway,3.85,-0.63

Portugal,8.00,1.18

Singapore,9.70,

Spain,5.55,-0.30

Sweden,3.95,-0.83

Switzerland,5.73,-0.46

UK,7.17,0.79

USA,8.55,2.02