James
6/13/2013
EnergyProd <- read.csv("EnergyProd.csv",
header=TRUE,nrows=62)
RenewProd <- subset(EnergyProd,
select=c("Year",
"Hydro",
"Geothermal",
"Solar",
"Wind",
"Biomass"))
head(RenewProd)
Year Hydro Geothermal Solar Wind Biomass
1 1949 1424722 NA NA NA 1549262
2 1950 1415411 NA NA NA 1562307
3 1951 1423795 NA NA NA 1534669
4 1952 1465812 NA NA NA 1474369
5 1953 1412859 NA NA NA 1418601
6 1954 1359772 NA NA NA 1394327
RenewProdLong <- melt(RenewProd,
id.vars="Year")
names(RenewProdLong) <- c("Year",
"Source",
"Power")
Year Hydro Geothermal Solar Wind Biomass
1 1949 1424722 NA NA NA 1549262
2 1950 1415411 NA NA NA 1562307
3 1951 1423795 NA NA NA 1534669
4 1952 1465812 NA NA NA 1474369
5 1953 1412859 NA NA NA 1418601
6 1954 1359772 NA NA NA 1394327
head(RenewProdLong)
Year Source Power
1 1949 Hydro 1424722
63 1949 Geothermal NA
125 1949 Solar NA
187 1949 Wind NA
249 1949 Biomass 1549262
2 1950 Hydro 1415411
require(ggplot2)
p <- ggplot(data=RenewProdLong,
aes(x=Year,y=Power ,fill=Source))
p <- p + geom_bar(stat='identity',
position=position_stack(width=2.9))
p <- p + scale_fill_brewer(type='qual',
palette=2)
p <- p + theme(legend.text = element_text(size=40),
axis.text = element_text(size=50),
axis.title.x = element_text(size=50),
axis.title.y = element_text(size=50))
p
names(EnergyProd)
[1] "Year" "Coal" "NatGas" "CrudeOil" "NGPL"
[6] "TotalFF" "Nuclear" "Hydro" "Geothermal" "Solar"
[11] "Wind" "Biomass" "TotalRenew" "Total"
require(plyr)
NewProd <- join(RenewProdLong,
EnergyProd[, c(1,13,14)],
by="Year")
head(NewProd)
Year Source Power TotalRenew Total
1 1949 Hydro 1424722 2973984 31722160
2 1949 Geothermal NA 2973984 31722160
3 1949 Solar NA 2973984 31722160
4 1949 Wind NA 2973984 31722160
5 1949 Biomass 1549262 2973984 31722160
6 1950 Hydro 1415411 2977718 35540384
q <- ggplot(data=NewProd,
aes(x=Year,y=Power/Total,
fill=Source))
q <- q + geom_bar(stat='identity',
position=position_stack(width=2.9))
q <- q + scale_fill_brewer(type='qual',
palette=2)
q <- q + theme(legend.text = element_text(size=40),
axis.text = element_text(size=50),
axis.title.x = element_text(size=50),
axis.title.y = element_text(size=50))