PURPOSE OF DATA VISUALIZATION
In the world of data we observe how much it is important to visualize data and hence saving time ,but at last what is important is that the data visual should interpret the message for which it has been made.
Just think about it how much time time it will take to explain what data says by just looking at data itself ( I mean lots of figures) Or by looking at the table that has been made from it.
Imagine how much time it saves specially for the decision makers.
Hence we now discuss how to perform data visualization and present data in R.
In this tutorial, we will create the following visualizations:
- Line Graph
- Bar Graph
- Scatter plot
- Pie Chart
1.1 Line Graph
What is the use of Line Graph?
It is used commonly used for time-series data.
For Example :
To know the figure of annual rainfall over time.
To know how many people eat Burger in a restaurant etc.
How to plot Line Graph in R?
To Plot the data set “UsaPopulation.csv” in R ,following are the steps
# import data in R : data1<- read.csv(file.choose(),header=TRUE,stringsAsFactor=FALSE)
# plot 2012 Population : plot(data1$2012[1:51],type=”l”,col=”red”)
# label X axis : axis(1,lab=”data1$states”,las=”2”)
# label Y axis : axis(2,las=”1”)
# Creating title with fonts : title(main=”Population”,col.main=”Red”,font.main=4)
1.2 Bar Graph
What is the use of bar graph in data visualization?
Suppose a milkman wants to know on which day his sale was maximum,the easy way to do this is through bar charts.
Bar chart is the chart with rectangular bars with length proportional to the value they represent.
#import data in R : read.csv(file.choose(),header=TRUE) Data1
#Count of male and female: bar1<- table(Book2$Sex)
# Plot bar of Sex with color: barplot(bar1,col=c(“red”,”blue”))
Scatter Plot is used to show the relationship between two quantitative variable.
Positive correlation : Value of Y increase with X.
Negative Correlation : Value of Y decreases with X.
No correlation : No relationship between X and Y.
#import data in R : read.csv(file.choose(),header=TRUE) Mtcars data
#plot scatter plot of mtcars$mpg: plot(mtcars$mpg)
#correlation through scatter plot between mpg and hp: plot(mtcars$mpg,mtcars$hp).
When to use histogram?
If we have numerical data or if we need to see frequency distribution of data we use histogram.
#import data: read.csv(file.choose(),header=TRUE) Mtcars data
#plot histogram : hist(mtcars$mpg)
#plot histogram with breaks and color : p4<- hist(mtcars$mpg,breaks=14,col=rainbow(14),labels=T)
Pie Chart is a circular graph used to show relative contribution that different categories contributes to an overall total and are generally used to show proportional or percentage data.
#import data in R : read.csv(file.choose(),header=TRUE,stringsAsFactors=FALSE)employee
#make Pie Chart : pie(Employee$SAL)
#modify pie chart: pie(Employee$SAL,main=”Salary Pie Chart”.col.name= “Darkgreen”,labels=Employee$ENAME,col=rainbow(14))
#Percentage of salaries as labels:
#add percentages to labels
Lbls<- paste(Lbls,”%”,sep= “ ”)
pie(Employee$SAL,main= “Salary Pie Chart”,labels=lbls,col=rainbow(14)).