One of the first steps with any statistical analysis, whether for hypothesis testing or predictive analytics or even a Kaggle competition, is checking the relationship between different variables. Checking if a pattern exists.
Graphs are a fantastic and visual way of identifying such relationships.
However, numerous readers kept getting stuck while selecting graphs for categorical variables and many friends asked if there was a standard rule for graph selection. With that in mind, please see below a cheatsheet for graphical selection for both quantitative (numeric) and categorical ( character -gender, disease type, etc.) variables.
|Histograms, Density plot, Box plot|
|Bar chart (freq/ count), Pie chart (freq/ count/%)|
|Bar chart, pie chart, frequency table, line chart|
|Stacked Column Chart, combination chart (typical bar chart with trendlines)|
|Stacked or side-by-side bar charts, heat maps. Any basic graph, with Color/shape code for one of the quant variables.|
|Stacked or side-by-side bar charts, Scatter plots. Any basic graph, with Color/shape code for one of the quant variables.|
3+ variables of any type
|Please check if you really need so many variables in a single graph. Side-by-side graphs may be a better option, or graphs with filters (if possible based on the programming language)|
These are merely guidelines and are language-agnostic, so you may choose to implement them in your choice of programming language ( R, Python, SAS, MATLAB, etc.) . However, if you prefer, code implementations in R and Python are provided in the links below:
- Charts in R :
- Charts in Python :
- This link contains code and images to create stunning graphs (box plots, histograms, heatmaps, bubble charts, etc) using MATPLOTLIB library, like the one shown above.
Hope you find this cheatsheet useful! Feel free to share your thoughts and comments. Adieu!