## File of R commands for Marlboro's heating oil data # Get ggplot2 into the action first. You may need to "install.packages(ggplot2)" first (after that step you still need to do the libary command). library(ggplot2) # Read and attach the data: oil=read.csv("/Users/matt/Documents/EAC/OIL/oilreadable.csv", header=TRUE) attach(oil) # Some variable amalgamations: # Technical ones: Presser = Presser.West + Presser.2 Campus.Center = Campus.Center.1 + Campus.Center.2 + New.THC Happy.Valley = Happy.Valley.1 + Happy.Valley.2 Plant.Ops = Maintenance + New.Maintenance # Groupings: CC.Whittemore.Serkin = Theater + Campus.Center + Serkin Library.Science = Library + Science South.Of.South.Road = Presser + Appletree + Pottery.Shed + Perrine On.Campus.Dorms = Howland + Schrader + Halfway + All.The.Way + Out.Of.The.Way + Random.North + Hendricks + Happy.Valley + Random.South Off.Campus = Cottage.5 + Cottage.1 + Cottage.2 + Cottage.3 + Cottage.4 + MacArthur.House + Capt.Dan.House + Red.House + Cabin.1 + Cabin.2 + Marlboro.North + Whittemore.House + Cottage.6 + Christie # not grouped: Dining.Hall, Dalrymple, Persons, Admissions, Plant.Ops. # And all-in: Total = CC.Whittemore.Serkin + Library.Science + South.Of.South.Road + On.Campus.Dorms + Off.Campus + Dining.Hall + Dalrymple + Persons + Admissions + Plant.Ops # The subsets in a vector: Building.Groups= c(CC.Whittemore.Serkin, Library.Science, South.Of.South.Road, On.Campus.Dorms, Off.Campus, Dining.Hall, Dalrymple, Persons, Admissions, Plant.Ops) Building.Group.Labels= c("CC.Whittemore.Serkin", "Library.Science", "South.Of.South.Road", "On.Campus.Dorms", "Off.Campus", "Dining.Hall", "Dalrymple", "Persons", "Admissions", "Plant.Ops") Buildings = c("Dining.Hall", "Dalrymple", "Persons", "Admissions", "Plant.Ops","Theater", "Campus.Center", "Serkin","Library", "Science","Presser", "Appletree", "Pottery.Shed", "Perrine","Howland","Schrader","Halfway", "All.The.Way", "Out.Of.The.Way", "Random.North", "Hendricks", "Happy.Valley", "Random.South","Cottage.5", "Cottage.1", "Cottage.2", "Cottage.3", "Cottage.4", "MacArthur.House", "Capt.Dan.House","Red.House", "Cabin.1", "Cabin.2", "Marlboro.North", "Whittemore.House", "Cottage.6", "Christie") # Different Groupings. Residential = On.Campus.Dorms + Off.Campus Non.Residential = Total - Residential ## Time series plot for total oil use: plot(Total/1000~Financial.Year, main="Heating Oil Use on the Undergraduate Campus", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(0,100), type="l", frame.plot=FALSE, las=1) #total1.pdf qplot(Financial.Year, Total/1000, main="Heating Oil Use on the Undergraduate Campus", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(0,100), geom="line") # Smoothed (not zero-scaled): # Varying span changes the wiggliness of the fit: higher is less wiggly. #total2.pdf qplot(Financial.Year, Total/1000, main="Heating Oil Use on the Undergraduate Campus", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(75,100), geom=c("point","smooth"), span=0.9) # Smoothed (not zero-scaled): # Lowering span to the point that we get a line that hits all the points. #total3.pdf qplot(Financial.Year, Total/1000, main="Heating Oil Use on the Undergraduate Campus", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(75,105), geom=c("point","smooth"), span=0.4) # Can we break down the components a little? Or a lot? #totalstacked barplot(rbind(Non.Residential/1000,On.Campus.Dorms/1000,Off.Campus/1000), main="Heating Oil Use by Building Type", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(0,140), col=c("darkblue","darkred","darkgreen"),legend = c("Acad/admin","Dorms","Off-Campus"),names.arg=Financial.Year) #totalbeside barplot(rbind(Non.Residential/1000,On.Campus.Dorms/1000,Off.Campus/1000), beside=TRUE, main="Heating Oil Use by Building Type", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(0,80), col=c("darkblue","darkred","darkgreen"),legend = c("Acad/admin","Dorms","Off-Campus"),names.arg=Financial.Year) #totalstacked2 barplot(rbind(CC.Whittemore.Serkin/1000, Library.Science/1000, South.Of.South.Road/1000, On.Campus.Dorms/1000, Off.Campus/1000, Dining.Hall/1000, Dalrymple/1000, Persons/1000, Admissions/1000, Plant.Ops/1000), main="Heating Oil Use by Building Group", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(0,140), col=rainbow(10), names.arg=Financial.Year) legend("topright",Building.Group.Labels, fill=rainbow(10), cex=0.5) #totalbeside2 barplot(rbind(CC.Whittemore.Serkin/1000, Library.Science/1000, South.Of.South.Road/1000, On.Campus.Dorms/1000, Off.Campus/1000, Dining.Hall/1000, Dalrymple/1000, Persons/1000, Admissions/1000, Plant.Ops/1000), main="Heating Oil Use by Building Group", ylab="Volume of Oil Used (1000s of gallons)", xlab="Financial Year", ylim=c(0,40), col=heat.colors(10), names.arg=Financial.Year, beside=TRUE) legend("topright",Building.Group.Labels, fill=heat.colors(10), cex=0.5) #totalstacked3 barplot(rbind(Dining.Hall, Dalrymple, Persons, Admissions, Plant.Ops,Theater, Campus.Center, Serkin,Library, Science,Presser, Appletree, Pottery.Shed, Perrine,Howland,Schrader,Halfway, All.The.Way, Out.Of.The.Way, Random.North, Hendricks, Happy.Valley, Random.South,Cottage.5, Cottage.1, Cottage.2, Cottage.3, Cottage.4, MacArthur.House, Capt.Dan.House,Red.House, Cabin.1, Cabin.2, Marlboro.North, Whittemore.House, Cottage.6, Christie), main="Heating Oil Use by Building", ylab="Volume of Oil Used", xlab="Financial Year", col=rainbow(35), names.arg=Financial.Year) #totalbeside3 barplot(rbind(Dining.Hall, Dalrymple, Persons, Admissions, Plant.Ops,Theater, Campus.Center, Serkin,Library, Science,Presser, Appletree, Pottery.Shed, Perrine,Howland,Schrader,Halfway, All.The.Way, Out.Of.The.Way, Random.North, Hendricks, Happy.Valley, Random.South,Cottage.5, Cottage.1, Cottage.2, Cottage.3, Cottage.4, MacArthur.House, Capt.Dan.House,Red.House, Cabin.1, Cabin.2, Marlboro.North, Whittemore.House, Cottage.6, Christie), main="Heating Oil Use by Building", ylab="Volume of Oil Used", xlab="Financial Year", col=rainbow(35), names.arg=Financial.Year, beside=TRUE) legend("topright",Buildings, fill=rainbow(35), cex=0.25) ## Time series plot for total cost: Total.Cost = Total*Oil.Price plot(Total.Cost/1000~Financial.Year, main="Cost of Oil Use on the Undergraduate Campus", ylab="Cost ($1000 units)", xlab="Financial Year", ylim=c(0,300), type="l", frame.plot=FALSE, las=1) #cost1.pdf qplot(Financial.Year, Total.Cost/1000, main="Cost of Oil Use on the Undergraduate Campus", ylab="Cost ($1000 units)", xlab="Financial Year", ylim=c(0,300), geom="line") # Smoothed. #cost2.pdf qplot(Financial.Year, Total.Cost/1000, main="Cost of Oil Use on the Undergraduate Campus", ylab="Cost ($1000 units)", xlab="Financial Year", ylim=c(0,300),geom=c("point","smooth")) ## An alternative universe where no new building has happened since 2000. # Need to remove Serkin, Out Of The Way, New THC and the library extension. # The last is done by subbing in the average value from 2000-2003. Library.Alt = Library Av = mean(Library[1:4]) Library.Alt[5:length(Library)] = Av Total.Alt = Total - (Serkin + Out.Of.The.Way + New.THC + Library) + Library.Alt plot(Total.Alt/1000~Financial.Year, main="Heating Oil Use on the Undergraduate Campus (New Buildings Removed)", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", ylim=c(0,100), type="l", frame.plot=FALSE, las=1) # A graph with both on (not zero-scaled): #alt1 plot(Total/1000~Financial.Year, main="Heating Oil Use on the Undergraduate Campus", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", ylim=c(75,100), xlim=c(2000,2012), type="l", frame.plot=FALSE, las=1) lines(Total.Alt/1000~Financial.Year, type="l", lty=2) legend("bottomright", c("actual","new building omitted"), lty=1:2) ## Effects of insulation work # Individual buildings, with Year 0 set to be the year before # insulation started and indexed to have 100 as the average of # the previous 5 years' totals (plotted as year 0) # Dalrymple: Year 0 is 2009. Dal.Av = mean(Dalrymple[5:9]) Dalrymple.Ins = c(100, 100*Dalrymple[10:length(Dalrymple)]/Dal.Av) # Dining Hall and Mather: Year 0 is 2010. Din.Av = mean(Dining.Hall[6:10]) Dining.Hall.Ins = c(100, 100*Dining.Hall[11:length(Dining.Hall)]/Din.Av) # Howland How.Av = mean(Dining.Hall[7:11]) Howland.Ins = c(100, 100*Dining.Hall[12:length(Howland)]/How.Av) # the graph (not zero-scaled) LL= max(length(Dalrymple.Ins)-1,length(Dining.Hall.Ins)-1) Ymin = min(60, min(Dalrymple.Ins), min(Dining.Hall.Ins),min(Howland.Ins)) Ymax = max(110, max(Dalrymple.Ins), max(Dining.Hall.Ins), max(Howland.Ins)) #newins.pdf plot(Dalrymple.Ins ~ c(0:LL), main="Oil Use in Newly Insulated Buildings", sub="(Indexed at 100 for the average of the five years prior to work starting, which is plotted as Year 0)", ylab="Oil Use Index", xlab="Years since work started", type="l", frame.plot=FALSE, las=1, ylim=c(Ymin,Ymax), col="blue", xlim=c(0,4)) lines(Dining.Hall.Ins ~ c(0:(length(Dining.Hall.Ins)-1)), col="red") lines(Howland.Ins ~ c(0:(length(Howland.Ins)-1)), col="green") legend("topright", c("Dalrymple", "Dining Hall and Mather", "Howland"), col=c("blue","red", "green"), lty=1) ## Individual plots for subsets of buildings. plot(CC.Whittemore.Serkin/1000~Financial.Year, main="Heating Oil Use in the Campus Center, Whittemore Theater and the Serkin Building", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,14)) plot(Library.Science/1000~Financial.Year, main="Heating Oil Use in the Library and Science Building", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,14)) plot(South.Of.South.Road/1000~Financial.Year, main="Heating Oil Use in the South-of-South-Road Group", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,8)) #oncamp.pdf plot(On.Campus.Dorms/1000~Financial.Year, main="Heating Oil Use in On-Campus Dorms", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,30), xlim=c(2000,2012)) plot(Off.Campus/1000~Financial.Year, main="Heating Oil Use in Off-Campus Housing", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,20)) #dinmath.pdf plot(Dining.Hall/1000~Financial.Year, main="Heating Oil Use in the Dining Hall and Mather", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,14), xlim=c(2000,2012)) #dalrymple.pdf plot(Dalrymple/1000~Financial.Year, main="Heating Oil Use in Dalrymple", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,6), xlim=c(2000,2012)) plot(Persons/1000~Financial.Year, main="Heating Oil Use in Person's Auditorium", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,10)) plot(Admissions/1000~Financial.Year, main="Heating Oil Use in the Admissions Building", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,3)) plot(Plant.Ops/1000~Financial.Year, main="Heating Oil Use in the Maintenance Building", ylab="Volume of Oil Used (1000 gallon units)", xlab="Financial Year", type="l", frame.plot=FALSE, las=1, ylim=c(0,3)) # Tidy up. detach(oil) ## Let's now look at just 2011. # Read and attach the data: oil2011=read.csv("/Users/matt/Documents/EAC/OIL/2011.csv", header=TRUE) attach(oil2011) # pie charts are ace. #2011pie pie(X2011.Use, labels=Building, main="Breakdown of Heating Oil Use for FY2011", radius = 1) # fy2011size.pdf qplot(Building, data=oil2011, geom="bar", weight=X2011.Use, fill=Category, main="Breakdown of Heating Oil Use for FY2011", xlab=NULL) + geom_bar(width=0.1) + coord_flip() +scale_y_continuous("Oil used (gallons)") oil2011 = transform(oil2011, Building = reorder(Building, X2011.Use), Category = reorder(Category, X2011.Use)) # A dotchart. #2011dotchart.pdf dotchart(X2011.Use, labels=Building, main="Breakdown of Heating Oil Use for FY2011", xlab="gallons", groups=Category, cex=0.8, gcolor=c("darkred", "darkblue", "darkgreen")) # fy2011alpha.pdf qplot(Building, data=oil2011, geom="bar", weight=X2011.Use, fill=Category, main="Breakdown of Heating Oil Use for FY2011", xlab=NULL) + geom_bar(width=0.1) + coord_flip() +scale_y_continuous("Oil used (gallons)") # Tidy up. detach(oil2011) ## Heating Degree Days hdd=read.csv("/Users/matt/Documents/EAC/OIL/hdd.csv", header=TRUE) attach(hdd) Efficiency = Oil/Heating.Degree.Days #eff.pdf qplot(Year, Efficiency, main="Efficiency (with a 68F baseline)", ylab="Efficiency", xlab="Financial Year", ylim=c(0,12), geom="line") # Tidy up. detach(hdd)