Forum Discussion
R Control Chart
Here's is an example of creating a histogram with a density distribution line.
hist(dataset$Age,
main = "Customer Count by Age",
ylab="Customer Count",
xlab="Customer Age",
xlim = c(18, 100),
border="black",
breaks=20,
col=c("lightyellow", "lightblue"),
las=1,
probability = TRUE
)
lines(density(dataset$Age),lty="dotdash", lwd=4, col="red")Here's an example of creating a barblot
barplot(dataset$'Sales Revenue',
names.arg = dataset$'Age Group',
main = "Sales Revenue by Customer Age Group",
col = c("red","yellow","orange","blue", "green")
)
minValue <- 0
maxValue <- max(as.vector(dataset$'Sales Revenue'))
yTicks <- seq(from=minValue, to = maxValue, length.out = 10)
yTicks <- pretty(yTicks)
yTickLabels <- paste("$",format(yTicks/1000, , big.mark=","), "K",sep="")
axis(2, at=yTicks, labels = yTickLabels, lty = 1, las=1, cex.axis=0.7 )Of course, these are simple examples using the built-in R graphics functionality. You can also use a richer graphics package such as lattice or ggplot2 to create some really detailed charts and graphs.
Is this what you are looking for?
Thanks Ted, this is along the same lines, but I am interested more in an "xbar" chart and also looking for a simple R script to create a Pareto chart for my customers.
Thank you for the scripts for the Histogram and Bar Plot, I will also be adding this to my arsenal.
- MawashiKid9 years agoResolver II
RE: also looking for a simple R script to create a Pareto chart
In order to use any chart -that is part of a R Visualization package library - it's logical to first make sure it's installed.install.packages('<yourPackage>')
Now considering the huge amount of R package visualization libraries, there may be a few ways to reproduce what you want. Note that I don't consider myself an R guru at this stage, still here's a couple of basic samples.
qcc library...library(qcc) defect <- c(80, 27, 66, 94, 33) names(defect) <- c("price code", "schedule date", "supplier code", "contact num.", "part num.") pareto.chart(defect, ylab = "Error frequency", col=heat.colors(length(defect)))ggplot2 library...
library(ggplot2) counts <- c(80, 27, 66, 94, 33) defects <- c("price code", "schedule date", "supplier code", "contact num.", "part num.") dat <- data.frame( count = counts, defect = defects, stringsAsFactors=FALSE ) dat <- dat[order(dat$count, decreasing=TRUE), ] dat$defect <- factor(dat$defect, levels=dat$defect) dat$**bleep** <- cumsum(dat$count) dat ggplot(dat, aes(x=defect)) + geom_bar(aes(y=count), fill="blue", stat="identity") + geom_point(aes(y=**bleep**)) + geom_path(aes(y=**bleep**, group=1))
I haven't played much with x-Bar chart though I'll check if I can find something... Anyway hope this helps