Barchart, Pareto
--- "Kapoor, Bharat " <k at chicagogsb.edu> wrote:
Hello Well I am relatively new so some of these issues may not fall under the subject that I have used. 1. How do I do a Pareto.
You might want to have a look at the qcc package. See http://www.stat.unipg.it/~luca/Rnews_2004-1-pag11-17.pdf for some information Following is the approach
I took. My data looks like this df2_9 Reaason.for.failure Frequency 1 Phy Conn 1 2 Power failure 3 3 Server software 29 4 Server hardware 2 5 Server out of mem 32 6 Inadequate bandwidth 1 I modified the data using:
df <-
df2_9[order(df2_9$Frequency,decreasing=TRUE),]
x$Percent <- 100*(x$Frequency)/(sum(x$Frequency))
ReasonCode Frequency ROF Percent 5 OOM 32 Out of Momeory 47.058824 3 SS 29 Server Software 42.647059 2 PF 3 Power failure 4.411765 4 SH 2 Server h/w 2.941176 1 PC 1 Physical Conn 1.470588 6 IB 1 Insuff b/w 1.470588 barplot(x$Percent, space=0, names.arg=x$ReasonCode, main="Pareto", legend.text=x$ReasonCode, ylab="% error") Here are my questions: 1. I could not print the data in ROF column below the bar charts, How to get full labels for each bar insted I createda new coumn ReasonCode just to fit below the bars.
Given the lenght of the names you may have a problem. ?mtext is the obvious way but the names are too long. Have a look at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/80007.html for rotating the labels or use the staxlab function in plotrix (see below)
2. Can I color code each bar differently 3. How to set limit on the y-axis - by deafult it shows 40, I want it show Y-axis till 50?
library(plotrix) bp <- barplot(x$Percent, space=0, names.arg=x$ReasonCode, main="Pareto", legend.text=x$ReasonCode, ylab="% error", col=1:5, ylim=c(0,50), xaxt="n") staxlab(side=1, 1:6, x[,3])
4. How to display value of each bar inside or on top of it?
?text