library(PASWR2)
## Loading required package: ggplot2
## Loading required package: lattice
## Loading required package: e1071
## Warning: package 'e1071' was built under R version 3.1.1
## Loading required package: grid
levels(PAMTEMP$month)
##  [1] "Apr" "Aug" "Dec" "Feb" "Jan" "Jul" "Jun" "Mar" "May" "Nov" "Oct"
## [12] "Sep"
PAMTEMP$month <- factor(PAMTEMP$month, levels = month.abb[1:12])
levels(PAMTEMP$month)
##  [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov"
## [12] "Dec"
YMP <- with(data = PAMTEMP,
       tapply(precip, list(year, month), sum)
       )
head(YMP)
##           Jan     Feb     Mar      Apr      May      Jun     Jul     Aug
## 1990  31.1008 26.8005  9.3001 121.1001 120.5002  77.0006 19.5006 35.7003
## 1991  31.4006 24.7004 32.0003 150.7006  59.4006  42.3004 28.3004  4.9001
## 1992   3.2003 16.5000 97.9005  66.0005  42.8003 111.1003 18.7003 95.1004
## 1993   1.3002 17.1004 15.3006 114.1005 108.5000  64.4005  3.1001 39.8001
## 1994  50.8005 52.4003  3.7008 129.3004  63.5005  33.0004      NA  3.4001
## 1995 104.9003 69.9000 56.7002  35.1005  33.1006   6.2002 29.2002  2.8001
##           Sep      Oct      Nov      Dec
## 1990  21.7001  76.5002  50.0008 103.3005
## 1991  94.1003 106.4007 119.0003  10.8005
## 1992  68.6003 213.4003  38.9004 130.6002
## 1993 100.3003  92.3003  34.2004 161.7007
## 1994  44.8006  93.4008  67.5000  97.0001
## 1995  48.2005  14.0002  53.8000 128.4000
library(plyr)
SEL <- ddply(PAMTEMP, .(year, month), summarize, TP = sum(precip))
head(SEL)
##   year month       TP
## 1 1990   Jan  31.1008
## 2 1990   Feb  26.8005
## 3 1990   Mar   9.3001
## 4 1990   Apr 121.1001
## 5 1990   May 120.5002
## 6 1990   Jun  77.0006
#
ggplot(data = SEL, aes(x = month, y = TP, fill = month)) + 
  geom_bar(stat = "identity") +
  labs(y = "Total Percipitation (1990-2010) in mm", x= "") +
  theme_bw() +
  guides(fill = FALSE)

#
SELY <- ddply(PAMTEMP, .(year), summarize, TP = sum(precip))
head(SELY)
##   year       TP
## 1 1990 692.5048
## 2 1991 704.0052
## 3 1992 902.8038
## 4 1993 752.1041
## 5 1994 638.8045
## 6 1995 582.3028
ggplot(data = SELY, aes(x = year, y = TP, fill = as.factor(year))) + 
  geom_bar(stat = "identity") +
  labs(y = "Total Percipitation (mm)") +
  theme_bw() +
  guides(fill = FALSE)