forked from xingyaochen/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrelations.Rmd
81 lines (64 loc) · 2.22 KB
/
correlations.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: "Correlations"
author: "Xingyao Chen"
date: "6/21/2017"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(cache = TRUE)
#install.packages('GGally')
#install.paackages('ggplot2)
#install.packages("qtlcharts", repos = 'http://cran.rstudio.com/')
library(GGally)
library(qtlcharts)
library(ggplot2)
my_fn <- function(data, mapping, ...){
p <- ggplot(data = data, mapping = mapping) +
geom_point(size=0.5) +
geom_smooth(method=lm, fill="blue4", color="blue1", ...)
return(p)
}
```
```{r}
mydat_small=read.csv('pollinator_visitation_fullData.csv')[,-1]
mydat_small$Experiment.Week=as.factor(mydat_small$Experiment.Week)
mydat_small$Plant.Number=as.factor(mydat_small$Plant.Number)
mydat_small$Pair=as.factor(mydat_small$Pair)
mydat_small_log=read.csv('pollinator_visitation_fullData_logTrans.csv')[,-1]
mydat_small_log$Experiment.Week=as.factor(mydat_small_log$Experiment.Week)
mydat_small_log$Plant.Number=as.factor(mydat_small_log$Plant.Number)
mydat_small_log$Pair=as.factor(mydat_small_log$Pair)
```
##Make a pairwise correlation plot for the untransformed data
```{r, warning=F}
boo=c()
for (i in 1:ncol(mydat_small)){
boo[i]=is.numeric(mydat_small[,i])
}
ggpairs(mydat_small[,boo][,-c(9:10,12:13)], lower=list(continuous=my_fn))
```
#This is a more complete correlation heatmap, and it's interactive! (Only on html verson of Rmd)
```{r}
p1=iplotCorr(mydat_small[,boo],mydat_small$visits, reorder=TRUE,
chartOpts=list(cortitle="Correlation Heatmap, Untransformed",
scattitle="Scatterplot | Visits",
scatcolors=c("red","lightblue")
))
p1
```
##Make a pairwise correlation plot for the log transformed data
```{r, warning=F}
ggpairs(mydat_small_log[,boo][,-c(9:10,12:13)], lower=list(continuous=my_fn))
```
#Now the interactive heatmap (Only on html verson of Rmd)
```{r, corheat}
p2=iplotCorr(mydat_small_log[,boo],mydat_small_log$visits, reorder=TRUE,
chartOpts=list(cortitle="Correlation Heatmap, Log10 Transformed",
scattitle="Scatterplot | Visits",
scatcolors=c("red","lightblue")
))
p2
```