library("gdata")
library("ggplot2")
library("dplyr")
library("plyr")
library("wesanderson")
data <- read.csv("/Users/ema 1/Desktop/sCOOL/Historical Archaeology/CemeteryDataFull.csv")
data$Born.Month <- factor(data$Born.Month, levels=c("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"))
data$Died.Month <- factor(data$Died.Month, levels=c("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"))

ggplot(data, aes(Sex, fill=Sex)) +
  geom_bar()+
  scale_fill_manual(values=wes_palette("Royal2"))

ggplot(data, aes(Period)) +
  geom_bar()

ggplot(data, aes(Died.Year, fill=FamilyPlot)) +
  geom_bar(position="dodge")

ggplot(data, aes(Died.Month, fill=Material)) +
  geom_bar(position="dodge")+
  ylim(0,5)

ggplot(data, aes(Died.Month, fill=Sex)) +
  geom_bar(position="dodge")+
  ylim(0,3)+
  scale_fill_manual(values=wes_palette("GrandBudapest2"))

ggplot(data, aes(Born.Month, fill=Sex)) +
  geom_bar(position="dodge")+
  ylim(0,3)+
  scale_fill_manual(values=wes_palette("GrandBudapest2"))

ggplot(data,aes(Born.Year,Age, colour=Sex)) +
  geom_point(size=5, shape=7)+
  geom_smooth()+
  scale_colour_manual(values=wes_palette("GrandBudapest"))

ggplot(data,aes(Died.Year, Age, colour=Sex)) +
  geom_point(size=4, shape=7)+
  geom_smooth()+
  scale_colour_manual(values=wes_palette("GrandBudapest"))

ggplot(data, aes(Died.Year, fill=Shape)) +
  geom_bar(position="dodge")

ggplot(data, aes(Died.Month, fill=Shape)) +
  ylim(0,6.5)+
  geom_bar(position="dodge")

Period <- factor(data$Period, levels = c("1885-1890", "1890-1895", "1895-1900", "1900-1905", "1905-1910", "1910-1915", "1915-1920", "1920-1925", "1925-1930", "1930-1935", "1935-1940", "1940-1945", "1945-1950", "1950-1955", "1955-1960", "1960-1965", "1965-1970", "1970-1975", "1975-1980", "1980-1985", "1985-1990", "1990-1995", "1995-2000", "2000-2005", "2005-2010", "2010-2015"))

wData <- data.frame(data$Name, data$Location, Period, data$Died.Year, data$Sex, data$Age, data$FamilyPlot, data$Shape, data$Material)

MyCrossTable <- table(wData[,3], wData[,2])
MyCrosFreq <- prop.table(MyCrossTable, 2)

ford <- function(x, cex.row.labels=1) {
#################################################
##  FORD'S "BATTLESHIP" DIAGRAM                ##
##  Loic JAMMET-REYNAL, may 2006               ##
##  Departement d'Anthropologie et d'Ecologie  ##
##  University of Geneva                       ##
##  jammetr1[at]etu.unige.ch                   ##
#################################################
 
    dim(x)[2] -> jmax # colonnes j
    dim(x)[1] -> imax # lignes i
 
    set.up <- function(xlim, ylim) {
        # setting up coord. system
        plot(    xlim,    # x
                ylim,     # y
                type="n", # no plotting
                axes = FALSE,
                asp = NA,
                xlab = "",
                ylab = "")
    }
 
    ## initialisation du device
    ## on divise par le nombre de colonnes + 1
    ## 1ere colonne : labels
    op <- par(mfrow=c(1, jmax+1), mar=c(5,0,2,0))
 
    # labels des lignes (colonne 1)
    set.up(c(0,1),             # x
           c(0.9, imax+1.10) ) # y
 
    for (i in 1:imax) {
        text(0.5,
               i+0.5,
              row.names(x)[i],
              font = 2, # boldface
              cex = cex.row.labels)
    }
 
    for (j in 1:jmax) { # colonnes j
        set.up(xlim = c(-60,60)*max(x),   # x
               ylim = c(0.9, imax+1.10) ) # y
 
        title(sub=colnames(x)[j],
              font.sub=2, # boldface
              cex.sub = 1.5)
 
        for (i in 1: imax) { # lignes i
            # le plus important. boite multipliee
            # par les parametres
            X <- c(-50,+50,+50,-50,-50)*x[i,j]
            Y <- c(i,i,i+1,i+1,i)
            polygon(X,
                    Y,
                    xpd=FALSE, 
                    col="black",
                    mar=c(0,0,0,0) )
        }
    }
}

ford(MyCrosFreq)+
  title("Location")

## numeric(0)
MyCrossTable2 <- table(wData[,3], wData[,9])
MyCrosFreq2 <- prop.table(MyCrossTable2, 2)

ford(MyCrosFreq2)+
  title("Material")

## numeric(0)
MyCrossTable3 <- table(wData[,3], wData[,7])
MyCrosFreq3 <- prop.table(MyCrossTable3, 2)

ford(MyCrosFreq3)+
  title("Family Plot")

## numeric(0)
MyCrossTable4 <- table(wData[,3], wData[,8])
MyCrosFreq4 <- prop.table(MyCrossTable4, 2)

ford(MyCrosFreq4)+
  title("Shape")

## numeric(0)