You are on page 1of 12

BAR CHART

AIM:
To create an Bar chart using Rstudio.

ALGORITHM:
1. Create an excel file as extension as .csv format.
2. Click on Rstudio.
3. In Console Window, Set the working directory.
4. Type an comment to read .csv file.
5. Type the coding to display the required file.
6. Use barplot to plot the bar chart.
7. Use xlab, ylab & main to name the x & y axis & title.
CODING:

> setwd("D:/Datavisual")
> traits<-read.csv("traits.csv")
> head(traits)
iq eyecolor gender mark
1 intelligent blue m 75
2 intelligent yellow f 33
3 intelligent brown m 12
4 intelligent red m 66
5 intelligent blue f 77
6 intelligent black m 89

> table(traits$eyecolor)
black blue brown red yellow
6 5 5 4 3
> barplot(table(traits$eyecolor))
> barplot(table(traits$eyecolor), xlab = "eye color", ylab = "persons", main = "Eye Color Bar
Chart", border = "green", col = "black")
> fem.eye<-table(traits$eyecolor[traits$gender=='f'])
> barplot(fem.eye, xlab = "eye color", ylab = "persons", main = "Eye Color Bar Chart",
border = "black", col = "blue")

RESULT:
Hence, created the bar chart.
HISTOGRAM
AIM:
To create an Histogram using Rstudio.

ALGORITHM:
1. Create an excel file as extension as .csv format.
2. Click on Rstudio.
3. In Console Window, Set the working directory.
4. Type an comment to read .csv file.
5. Type the coding to display the required file.
6. Use histogram to plot the bar chart.
7. Use xlab, ylab & main to name the x & y axis & title.
CODING:

> setwd("D:/Datavisual")
> traits<-read.csv("traits.csv")
> head(traits)
iq eyecolor gender mark
1 intelligent blue m 75
2 intelligent yellow f 33
3 intelligent brown m 12
4 intelligent red m 66
5 intelligent blue f 77
6 intelligent black m 89

> table(traits$eyecolor)
black blue brown red yellow
6 5 5 4 3
H<-table(traits$eyecolor)
> hist(H,xlab = "Weight",col = "black",border = "blue", xlim = c(3,7), ylim = c(0,3), breaks
= 5)

RESULT:
Hence, created an histogram.
PIE CHART
AIM:
To create an Pie chart using Rstudio.

ALGORITHM:
1. Create an excel file as extension as .csv format.
2. Click on Rstudio.
3. In Console Window, Set the working directory.
4. Type an comment to read .csv file.
5. Type the coding to display the required file.
6. Use pie chart to plot the bar chart.
7. Use xlab, ylab & main to name the x & y axis & title.
CODING:

> setwd("D:/Datavisual")
> traits<-read.csv("traits.csv")
> head(traits)
iq eyecolor gender mark
1 intelligent blue m 75
2 intelligent yellow f 33
3 intelligent brown m 12
4 intelligent red m 66
5 intelligent blue f 77
6 intelligent black m 89

> table(traits$eyecolor)
black blue brown red yellow
6 5 5 4 3
> H<-table(traits$eyecolor)
> pie(H, x, main = "City pie chart", col = rainbow(length(H)))

RESULT:
Hence, created an pie chart.

You might also like