Introduction

I used a dataset of number of Fortune 500 companies in different countries. To better analyze the data, I created a line chart to see the comparison of different countries.

Summarizing data

Firsly, I summariaze the dataframe to get a fisrt sight of the data.

df=read.csv("https://raw.githubusercontent.com/bctclc/sample_data_for_R_viz/master/fortune_500_by_country.csv")
summary(df)
##       year          China             U.S.           Japan       
##  Min.   :2000   Min.   : 10.00   Min.   :121.0   Min.   : 51.00  
##  1st Qu.:2005   1st Qu.: 17.50   1st Qu.:132.0   1st Qu.: 56.25  
##  Median :2010   Median : 48.50   Median :139.5   Median : 68.00  
##  Mean   :2010   Mean   : 59.65   Mean   :151.3   Mean   : 70.15  
##  3rd Qu.:2014   3rd Qu.:101.50   3rd Qu.:174.2   3rd Qu.: 81.25  
##  Max.   :2019   Max.   :129.00   Max.   :196.0   Max.   :107.00  
##      France        Germany           U.K.           other      
##  Min.   :27.0   Min.   :28.00   Min.   :17.00   Min.   :101.0  
##  1st Qu.:29.0   1st Qu.:29.00   1st Qu.:27.00   1st Qu.:113.8  
##  Median :31.0   Median :32.00   Median :30.50   Median :121.0  
##  Mean   :31.3   Mean   :31.75   Mean   :30.80   Mean   :124.3  
##  3rd Qu.:33.0   3rd Qu.:34.00   3rd Qu.:35.25   3rd Qu.:137.0  
##  Max.   :36.0   Max.   :36.00   Max.   :40.00   Max.   :155.0

Creating a line chart

library(ggplot2)
ggplot(data=df,aes(x=year))+
geom_line(aes(y=China,color="China"))+
geom_line(aes(y=U.S.,color="U.S."))+
geom_line(aes(y=Japan,color="Japan"))+
geom_line(aes(y=France,color="France"))+
geom_line(aes(y=Germany,color="Germany"))+
geom_line(aes(y=U.K.,color="U.K."))+
geom_line(aes(y=other,color="other"))+
ylab("Number of Fortune 500 companies")+
xlab("Year")+
ggtitle("Number of Fortune 500 companies in different countries")