RSS

R : Basic Bar and Pie Chart

07 May

Bar Chart

Lets take the data frame example from basic line plot.

x=data.frame(wt = c(105, 120, 120, 160, 120, 145, 175, 160, 185, 210),ht = (61, 62, 63, 65, 65, 68, 69, 70, 72, 75)
# Partition R workspace in 1 * 2 matrix
par(mfrow=c(1,2))
barplot(x$ht, ylab="Height", width=8, space=.3,xlim=c(1,100), main="Height Plot - Vertical Bars")
barplot(x$ht, xlab="Height", width=8, space=.3,xlim=c(1,100), horiz=T, main="Height Plot - Horizontal Bars")

 

Rplot

Group Bar Chart

Lets try to plot the group bar chart on 2013, 2014 rainfall from Jan-Dec (rainfall). beside=True play the trick here


y=as.matrix(sapply(z, as.numeric))
barplot(y, <strong>beside=T</strong>, main="Rainfall in 2013-14", col=c("blue","red"))

Rplot01

PIE Chart

Lets try to create pie chart with the rainfall data set (rainfall_2014). Try with simple pie chart.


pie(z$X2014, main="Rainfall in year 2014")

Rplot02

Lets try beautify the pie chart


pie(z$X2014, labels=z$Months, main="Rainfall in year 2014", radius=1.1, col=rainbow(length(z$Months)))

Rplot03

 
1 Comment

Posted by on May 7, 2015 in Basic Bar and Pie Chart, R Basics

 

Tags: , ,

One response to “R : Basic Bar and Pie Chart

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: