## 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:

**1.****Basic Visualization**

__Line Graph____Bar Graph____Scatter plot____Histogram____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=Simple

2=Bold

3= Italic

4=Bold Italic

## 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.

__Step__

**#import data in R : read.csv(file.choose(),header=TRUE) Data1**

BodyCap | Age | Height | Sex |

6.475 | 6 | 62.1 | male |

10.152 | 18 | 74.7 | male |

9.55 | 16 | 69.7 | male |

11.125 | 14 | 71 | female |

4.8 | 5 | 66 | female |

6.225 | 11 | 63.3 | female |

4.95 | 8 | 39.2 | female |

**#Count of male and female: bar1<- table(Book2$Sex)**

**# Plot bar of Sex with color: barplot(bar1,col=c(“red”,”blue”))**

**1.3**__Scatter plot__

__Scatter plot__

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).**

**1.4 Histogram**

**When to use histogram?**

**If we have numerical data or if we need to see frequency distribution of data we use histogram.**

__Steps__

**#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)**

** ****1.5**__Pie Chart__

__Pie Chart__

**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: **

**SAL_labels<- round(Employee$SAL/sum(Employee$SAL)*100,1)**

**SAL_labels**

**Lbls<- paste(Employee$ENAME,SAL_labels)**

**Lbls**

**#add percentages to labels**

**Lbls<- paste(Lbls,”%”,sep= “ ”)**

**pie(Employee$SAL,main= “Salary Pie Chart”,labels=lbls,col=rainbow(14)).**

** **