programming has become one of the best data analytics tools especially when it comes for visual analytics. A great community contribution makes it easier to learn, use and share for the effective visualization. It is imperative to say that proper visualization is a very important factor for data scientists & AI specialists. Even if you are only interested to work with business communication with impactful visualizations, R can provide you a comprehensive way of work where you have full freedom to play with your data and create useful graphs for your audiences. It is an open-sourced tool by the way. RStudio is the most favorable IDE(Integrated Development Environment) for R. ggplot2 is the most popular data visualization package in the R community. It was created by Hadley Wickham in 2005. It was implemented based on Leland Wilkinson’s Grammar of Graphics — a general scheme for data visualization which breaks up graphs into semantic components such as scales and layers. While using ggplot2, you provide the data, call specific function, map your desired variables to aesthetics, define graphical arguments, rest it will take care! For details, you can go through its documentation. tidyverse is a collecttion of packages for data science introduced by the same Hadley Wickham. ‘tidyverse’ encapsulates the ‘ggplot2’ along with other packages for data wrangling and data discoveries. More details can be found in its documentation. Let’s install the required packages first. You do not need to install any package more than once in our system unless willing to upgrade it. Note : If you install tidyverse, then you do not need to install ggplot2 separately! Now we need to load our packages. Unlike installing, loading packages is required every time you start your system. In this exercise we will use four datasets. Two of them are standard datasets and used worldwide for practicing data visualizations. these are iris and diamonds datasets. Other two are specially curated datasets for this work purpose. names.csv has the data of three female names’ uses along the years from 1880 to 2017 and life_expectency.csv contains contains fifteen countries’ life expectancy in years for 1967 and for 2007. Please download these two datasets either from my github repository or from google drive whichever is convenient. Note : all these datasets are open-sourced. Now, Let’s import the datasets Here are three options to check on your imported data, Image by AuthorImage by AuthorImage by AuthorAbout the FunctionsWe will use several functions from the ggplot2 package. These functions work together to yield the desired graphs. Every ggplot2 graph starts with the function ggplot() . It basically creates the coordinate system. Over this the graphical layers are added. The first argument of this function is the input dataset for the intended graph. Then comes the geom functions which add the layers of plotting on the coordinate system according to its geom i.e. geom_point, geom_line, geom_bar etc. Every geom function needs a mapping argument. This defines how the variables in the dataset are mapped to visual properties. The aesthetic function aes() is assigned to the mapping argument. The main arguments of the aes() function are axes augments-x, yand differentiating arguments like color, size, fill, alpha. The differentiating arguments become common featured arguments when they are put outside of the aes() function. ggtitle(), xlab(), ylab(), theme() these functions are used for the labelling and thematic attributes. Note : You can find detail of these functions in the help tab by executing the command — ?function_name , like ?geom_point. Image by AuthorThe functions can be organized in below templates Photo by Gábor Juhász on Unsplashdataset- iris Image by AuthorBasic Scatter Plot Image by AuthorScatter Plot with feature differentiation by color & shape Image by AuthorScatter Plot with feature differentiation by size & transparency Image by AuthorPhoto by Emma Louise Comerford on Unsplashdataset- names Basic Line Plot Image by AuthorLine Plot with feature differentiation by color & line type Image by AuthorPhoto by All Bong on Unsplashdataset- diamonds Image by AuthorBasic Bar Plot Image by AuthorBasic Bar Plot with polar transformation Image by AuthorBasic Bar Plot- 2 Image by AuthorStacked Bar Plot Image by AuthorStacked Bar Plot in same height Image by AuthorGrouped Bar Plot Stacked Bar Plot with polar transformation Image by AuthorStacked Bar Plot with polar transformation- 2 Image by AuthorPhoto by Viktor Forgacs on Unsplashdataset- iris Image by AuthorBasic Scatter Matrix Plot Image by AuthorScatter Matrix Plot with feature differentiation Image by AuthorPhoto by Clarisse Meyer on Unsplashdataset- diamonds Image by AuthorBasic Histogram Image by AuthorStacked Histogram dataset- diamonds Image by AuthorBasic Box Plot Image by AuthorGrouped Box Plot Image by AuthorBox Plot with polar transformation Image by Authorwant to believe that you find this writeup very helpful and I recommend you to practice further these graphs with your own datasets. This can be a good start for visual analytics and your journey towards data science !! Photo by Chirag Saini on Unsplash |