Hello everyone,
Thank you very much for helping. I created a reprex.
Please tell me if it doesn't work.
library(reprex)
MAN<-c("a","b","c","d")
MANAGER<-sample(MAN,300, replace = TRUE)
COMPLETED <-rnorm(300,14.41,1)
UPLOADED <-rnorm(300,16.1,1)
df<-data.frame(MANAGER,COMPLETED,UPLOADED)
View(df)
# Here is an example of what I want my graph to look like for everyone of my 4 area managers.
par(mfrow=c(1,3))
hist(df$COMPLETED[df$MANAGER=="b"], main = "Completed Inspections throughout the Day",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 12, xlim=c(0,24),ylim=c(0,20),
border = "black", col=rgb(1,0,0,0.5), axes=F)
axis(1, at = seq(0,24,1))
axis(2, at = seq(0,20,5))
box()
hist(df$UPLOADED[df$MANAGER=="b"],main = "Completed Uploads throughout the Day",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 12, xlim=c(0,24),ylim=c(0,20),
border = "black", col= rgb(0,0,1,0.5), at = seq(0,25,1), axes = F, add=F)
#> Warning in plot.window(xlim, ylim, "", ...): "at" is not a graphical
#> parameter
#> Warning in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...):
#> "at" is not a graphical parameter
axis(1, at = seq(0,24,1))
axis(2, at = seq(0,20,5))
box()
# Join Histograms
hist(df$COMPLETED[df$MANAGER=="b"], main = "Completed Inspections and Uploads throughout the Day",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 12, xlim=c(0,24),ylim=c(0,20),
border = "black", col=rgb(1,0,0,0.5), axes=F)
hist(df$UPLOADED[df$MANAGER=="a"],main = "Inspection Load Time",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 12, xlim=c(0,24),ylim=c(0,20),
border = "black", col=rgb(0,0,1,0.5), at = seq(0,25,1), axes = F, add=T)
axis(1, at = seq(0,24,1))
axis(2, at = seq(0,20,5))
box()
legend("topleft",c("Pink = Completed Inspections every Hour","Blue = Completed Uploads every Hour",
"Purple = Intersection every Hour"),
lty=c(1,1,1), bty="n", cex=0.75)
mtext("Inspections and Uploads Distributions for manager (a)", outer=TRUE, cex=1, line=-1) # title for manager A
#Instead of doing this for each manager, I want to:
# 1) Create a pdf and put the graphs of each area manager on a separate page
# 2) Do this in an efficient way. So, here is what is not working from below:
# 3) Add a title to every manager as shown from the mtext function above.
pdf(paste("work.pdf"))
# Histogram 1
par(mfrow=c(3,1))
for(i in unique(df$MANAGER)){
dev.new()
hist(df$COMPLETED[unique(df$MANAGER==i)], main = "Completed Inspections throughout the Day for",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 24, xlim=c(0,24),ylim=c(0,25),
border = "black", col=rgb(1,0,0,0.5), axes=F)
axis(1, at = seq(0,24,1))
axis(2, at = seq(0,25,5))
box()
dev.new()
#Histogram 2
hist(df$UPLOADED[unique(df$MANAGER==i)],main = "Completed Uploads throughout the Day",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 24, xlim=c(0,24),ylim=c(0,25),
border = "black", col= rgb(0,0,1,0.5), at = seq(0,25,1), axes = F, add=F)
axis(1, at = seq(0,24,1))
axis(2, at = seq(0,25,5))
box()
# Joint Histogram
dev.new()
hist(df$COMPLETED[unique(df$MANAGER==i)], main = "Completed Inspections and Uploads throughout the Day",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 24, xlim=c(0,24),ylim=c(0,25),
border = "black", col=rgb(1,0,0,0.5), axes=F)
hist(df$UPLOADED[df$MANAGER==i],main = "Inspection Load Time",
xlab= "Hours of the Day", ylab = "Frequency", breaks = 24, xlim=c(0,24),ylim=c(0,25),
border = "black", col=rgb(0,0,1,0.5), at = seq(0,25,1), axes = F, add=T)
axis(1, at = seq(0,24,1)) #value of 1 means x-axis
axis(2, at = seq(0,25,5)) # value of 2 means y-axis
box() ## box puts the graph in a confined box.
legend("topleft",c("Pink = Completed Inspections every Hour","Blue = Completed Uploads every Hour",
"Purple = Intersection every Hour"),
lty=c(1,1,1), bty="n", cex=0.8)
mtext("Inspections and Uploads Distributions manager", outer=TRUE, cex=1, line=-1) ## to add the name of the manager which is also a variable
}
dev.off()