Skip to content

Commit

Permalink
figures sent to CC for resubmission
Browse files Browse the repository at this point in the history
  • Loading branch information
rstudio committed Feb 1, 2015
1 parent 8148e60 commit 4c9a21b
Show file tree
Hide file tree
Showing 13 changed files with 1,081 additions and 198 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Depends: R (>= 3.1.2)
License: MIT, 2015, Ben Marwick
LazyData: true
Imports:
gridExtra,
knitr,
ggplot2,
reshape2,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(bayes_slope_test)
export(bayes_slopes_chrono_data)
export(bayes_test_slopes_chrono_data)
export(clean_lithics_data)
export(combine_lens_plots)
export(get_chrono_data)
export(get_lithics_data)
export(interpolate_chrono_data)
Expand Down
59 changes: 43 additions & 16 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,12 @@ get_lithics_data <- function(){

clean_lithics_data <- function(lithics){

# filter the data for display (remove some dates )
# filter the data for display (remove some dates that show inversions)
lithics$C14 <- as.numeric(as.character(lithics$C14))
lithics$C14[lithics$C14 %in% c(0.7, 15.0, 24)] <- NA

# filter anomalous spit

# filter anomalous spit, which has an usual depth value
lithics <- lithics[!(lithics$Spit == 62),]

# get rid of NA rows for total artefact count
Expand All @@ -635,7 +636,7 @@ clean_lithics_data <- function(lithics){
#' @export
#' @examples
#' \dontrun{
#' lithics_data_plotted <- plots_lithics_data(lithics_data, bayes_cp_result$cal.date.lo)
#' lithics_data_plotted <- plots_lithics_data(lithics_data_cleaned, bayes_cp_result$cal.date.lo)
#' }

plots_lithics_data <- function(lithics, cal.date.lo){
Expand All @@ -650,8 +651,9 @@ plots_lithics_data <- function(lithics, cal.date.lo){
ylab("Number of stone artefacts >6 mm") +
annotate("text", x = lithics$Spit, y = 615, label = round(lithics$C14, 0), size = 4) +
annotate("text", x = lithics$Spit, y = 615, label = round(lithics$OSL, 0), colour = "red", fontface="bold.italic", size = 4) +
annotate("text", x = 60, y = 615, label = "ka",size = 4) +
ylim(0,615)
annotate("text", x = 50, y = 615, label = "ka",size = 4) +
ylim(0,615) +
xlim(0,50)
p1
# save plot as SVG for finessing...
ggsave(file = "figures/Fig_6_lithics_over_time_from_1989_for_paper.svg")
Expand Down Expand Up @@ -878,8 +880,8 @@ clust <- chclust(diss, method = "coniss")
# remove NA d[is.na(d)] <- 0
strat_plot[is.na(strat_plot)] <- 0

# save plot to file
png("figures/stratplot.png",width = 1000, height = 500)
# save plot to file, this is figure 9
png("figures/Fig_9_stratplot.png",width=10, height=5, units="in", res=1200)
x <- strat.plot(strat_plot[,-ncol(strat_plot)] * 100,
scale.minmax = TRUE,
yvar = as.numeric(strat_plot$age),
Expand Down Expand Up @@ -940,19 +942,20 @@ lens_differences_raw <- function(){
library("reshape2")
dat_raw <- read.csv("data/Lithics_table_from_paper_on_1989_dig.csv")

dat_raw$part <- with(dat_raw, ifelse(Spit %in% c(37:40), 'above',
ifelse(Spit %in% c(41, 43, 62), 'lens',
ifelse(Spit %in% c(42, 44:49), 'below',
dat_raw$part <- with(dat_raw,
ifelse(Spit %in% c(37:40), 'above',
ifelse(Spit %in% c(41, 43, 62), 'lens',
ifelse(Spit %in% c(42, 44:49), 'below',
"who_cares"))))

dat_raw[10:15,] <- apply(dat_raw[10:15,], 2, as.numeric)

# combine Quartzite types
dat_raw$Quartzite <- dat_raw %>%
select(Local.Coarse.Grained.Quartzite,
Fine.Grained.Exotic.Quartzite,
Brown.Quartzite) %>%
rowSums(na.rm = TRUE)
dplyr::select(Local.Coarse.Grained.Quartzite,
Fine.Grained.Exotic.Quartzite,
Brown.Quartzite) %>%
rowSums(na.rm = TRUE)


# put things in order for the plot
Expand All @@ -977,6 +980,8 @@ p1 <- ggplot(dat_raw1, aes(variable, perc)) +

ggsave("figures/raw-materials-lens.png", width = par("din")[1] * 1.6)

raw_dat_long <- dat_raw1

p2 <- ggplot(dat_raw1, aes(part, perc, fill = variable)) +
geom_bar(stat="identity", position=position_dodge()) +
theme_minimal()
Expand Down Expand Up @@ -1008,6 +1013,7 @@ raw_table <- dcast(ret, part ~ variable, value.var = 'n')[,-1]
return(list(p1 = p1,
p2 = p2,
p3 = p3,
raw_dat_long =raw_dat_long,
raw_chi_fisher = raw_chi_fisher,
raw_table = raw_table))

Expand Down Expand Up @@ -1088,6 +1094,8 @@ p1 <- ggplot(dat_tech1, aes(variable, percentage)) +

ggsave("figures/tech-lens-difference.png", width = par("din")[1] * 1.6)

tech_dat_long <- dat_tech1


# The plot of the types in each zone by percentage of the entire count of types for spits
ggplot(dat_tech_all, aes(variable, percentage)) +
Expand Down Expand Up @@ -1120,11 +1128,30 @@ tech_chi_fisher <- fisher.test(tech_table, simulate.p.value=TRUE)
return(list(p1 = p1,
tech_chi_fisher = tech_chi_fisher,
tech_table = tech_table,
dat_tech1 = dat_tech1))
tech_dat_long = tech_dat_long))

}

############################################################
#' Combine raw materials and technology plots for upper-lens-lower
#'
#'
#'
#' @export
#' @examples
#' \dontrun{
#' lens_tech_and_raw_plot <- combine_lens_plots(lens_differences_tech_plot$p1,lens_differences_raw_plot$p1)
#' }

combine_lens_plots <- function(tech_dat_plot, raw_dat_plot) {

png("figures/Fig_10_combine_lens_plots.png",width=16, height=10, units="in", res=1200)

gridExtra::grid.arrange(raw_dat_plot, tech_dat_plot)

dev.off()

}


############################################################
Expand Down Expand Up @@ -1737,7 +1764,7 @@ g <- ggplot(perc_and_mass_m, aes(Taxon, value)) +
facet_grid(variable ~ Spit, scales = "free_y")

# save plot as PNG
ggsave(file = "figures/shell_from_1989_for_paper.png", g)
ggsave(file = "figures/Fig_14_shell_from_1989_for_paper.png", g, dpi = 1200)

return(g)

Expand Down
17 changes: 17 additions & 0 deletions man/combine_lens_plots.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
% Generated by roxygen2 (4.1.0.9001): do not edit by hand
% Please edit documentation in R/functions.R
\name{combine_lens_plots}
\alias{combine_lens_plots}
\title{Combine raw materials and technology plots for upper-lens-lower}
\usage{
combine_lens_plots(tech_dat_plot, raw_dat_plot)
}
\description{
Combine raw materials and technology plots for upper-lens-lower
}
\examples{
\dontrun{
lens_tech_and_raw_plot <- combine_lens_plots(lens_differences_tech_plot$p1,lens_differences_raw_plot$p1)
}
}

2 changes: 1 addition & 1 deletion man/plots_lithics_data.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Plots of the lithics raw data
}
\examples{
\dontrun{
lithics_data_plotted <- plots_lithics_data(lithics_data, bayes_cp_result$cal.date.lo)
lithics_data_plotted <- plots_lithics_data(lithics_data_cleaned, bayes_cp_result$cal.date.lo)
}
}

22 changes: 10 additions & 12 deletions vignettes/analysis-of-dates-lithics-shell-from-1989-excavations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bayes_slope_posteriors <- bayes_slope_difference(sed_rates_15_to_20_result$sub_O
# from a run so we can use that rather than redo the analysis. To
# redo the analysis, simply run the code in the previous chunk.
load("data/slopes_test_sub.rda")
summary(slopes_test_sub)
BEST:::summary.BEST(slopes_test_sub)
# print(slopes_test_sub)
# plot(slopes_test_sub)
# windows()
Expand All @@ -159,15 +159,8 @@ lithics_data <- get_lithics_data()
lithics_data_cleaned <- clean_lithics_data(lithics_data)
```


```{r get_interp, results='hide', include=FALSE}
# need these to get bayes_cp_result$cal.date.lo)
chrono_data_slopes_plot <- plotting_slopes_chrono_data(chrono_data_tidied)
bayes_cp_result <- bayes_cp_test(chrono_data_slopes_plot$dates_1989)
```

```{rplot-data}
lithics_data_plotted <- plots_lithics_data(lithics_data, bayes_cp_result$cal.date.lo)
lithics_data_plotted <- plots_lithics_data(lithics_data_cleaned, bayes_cp_result$cal.date.lo)
lithics_data_plotted$p1
# figures/Fig_6_lithics_over_time_from_1989_for_paper.svg
```
Expand All @@ -183,22 +176,27 @@ lithics_rawmaterials_plotted <- plots_lithics_rawmaterials(lithics_data,

```{r strat-plot}
lithics_rawmaterials_stratplotted <- stratiplot_lithics(lithics_rawmaterials_plotted$plot2)
# figures/stratplot.svg
# figures/Fig_9_stratplot.png
```


```{r lens-raw-materials}
lens_differences_raw_plot <- lens_differences_raw()
lens_differences_raw_plot$p1
raw_fish_pval <- formatC(round(lens_differences_raw_plot$raw_chi_fisher$p.value, 4), big.mark=",",format="f", drop0trailing = TRUE)
```

```{r lens-tech-difference}
lens_differences_tech_plot <- lens_differences_tech()
lens_differences_tech_plot$p1
tech_fish_pval <- round(lens_differences_tech_plot$tech_chi_fisher$p.value, 3)
```

```{r lens-tech-and-raw-plot, results = "asis"}
lens_tech_and_raw_plot <- combine_lens_plots(lens_differences_tech_plot$p1,lens_differences_raw_plot$p1)
lens_tech_and_raw_plot
cat("<p><img src='figures/Fig_10_combine_lens_plots.png'</p>")
```


Chi square tests indicate that the differences in raw material proportions between all three assemblages are highly significant (p = `r raw_fish_pval`), although the differences in technological composition are not significant (p = `r tech_fish_pval`), most likely due to small sample size (n = 10 for types in the assemblage below the lens).


Expand Down
Binary file added vignettes/figures/Fig_10_combine_lens_plots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4c9a21b

Please sign in to comment.