Plotting Ports with Throughput versus Annual Growth in R
Dr. Vipul Patel
Assistant Professor - Business Analytics / Marketing Analytics Trainer - PowerBI, Microsoft Excel, Business Analytics (R and Python)
In the article, I will try to explain how to plot various plots using the latest year’s sea port throughput against the port’s annual average growth rate in R. Dataset used can be downloaded from following website
https://essentials.togaware.com/ports.xlsx
The spread sheet contains multiple tables. We will extract the various tables of data from the spreadsheet with specific cell ranges for visualization.
Let’s load the spread sheet into R.
Now we are interested in the first two tables in the spreadsheet. The first table is found to range over rows 2 and 4, with row 2 containing the port names.
Let’s extract the required data as “mydata” and transpose it using command t() and then ensure it remains a dataframe.
Lets give names to three columns – port, LatestYear, AnnualGrowthRate and convert “Latest Year” and “Annual Growth Rate” as numeric which are currently treated as character.
Now, the ports are grouped into mixed and bulk ports. This information is contained in another table within the spreadsheet corresponding to rows 7 to 17 and columns 1 and 2 (with row 6 being the column names).
Now reshape the port type data in such a manner that the resulting dataset will have two columns named type and port.
Now lets merge the two datasets (mydata and port_type) into one dataset.
Resulting table will look like below:
Now, convert variable type as factor
Now the data is ready to generate the plot.
This will generate following beautiful plot.
Excellent…its look beautiful..isnt it?