-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_plots.R
65 lines (58 loc) · 2.93 KB
/
make_plots.R
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
source('startup.R')
ww <- 6
hh <- 4
CH.long <- melt(df, id.vars=names(df)[1:10],
variable.name='periodo', value.name='recapturas')
CH.long$periodo <- as.numeric(gsub("X", "", x=CH.long$periodo))
CH.long$numero <- CH.long$Tag_num
CH.long$genero <- CH.long$Sex
CH.long2 <- droplevels(subset(CH.long, !is.na(recapturas) & recapturas>0))
CH.long2 <- CH.long2[,c('numero', 'periodo', 'recapturas', 'genero',
'Event', 'length')]
CH.long2$data <- "real"
g <- ggplot(CH.long2, aes(numero, y=periodo, color=factor(Event))) +
geom_jitter(width=0, alpha=.5, height=.1) + facet_grid(genero~data)
ggsave('plots/CH_matriz.png', g, width=7, height=5)
## Simulate data to compare to real
test <- simulator(1)
CH2.long <- melt(test$simdata$CH)
names(CH2.long) <- c("numero", "periodo", "recapturas")
CH2.long <- merge(CH2.long, y=data.frame(length=test$simdata$lengths,
numero=1:test$simdata$I),
by='numero')
CH2.long$genero <- sample(x=c("M", "F"), size=nrow(CH2.long), repl=TRUE)
CH2.long$Event <- 1
CH2.long2 <- droplevels(subset(CH2.long, !is.na(recapturas) & recapturas>0))
CH2.long2$data <- "simulado"
CH.all <- rbind(CH.long2, CH2.long2)
g <- ggplot(CH.all, aes(numero, y=periodo, color=factor(Event))) +
geom_jitter(width=0, size=.1, alpha=.5, height=.1) + facet_grid(~data)
ggsave('plots/CH_matriz_all.png', g, width=7, height=5)
## Use both simulated and real or just real?
CH.long2 <- CH.all
g <- ggplot(CH.long2, aes(recapturas)) + geom_bar() + scale_y_log10() +
xlab("Numero de recapturas en un periodo") + facet_grid(genero~data)
ggsave('plots/recapturas_periodo.png', g, width=ww, height=hh)
xx <- ddply(CH.long2, .(numero, genero, data), summarize,
recapturas.total=sum(recapturas),
recapturas.periodo=length(recapturas),
periodo.rango=max(periodo)-min(periodo),
periodo.primero=min(periodo),
length=length[1])
g <- ggplot(xx, aes(recapturas.total)) + geom_bar() +# scale_y_log10() +
xlab("Numero de recapturas") +facet_grid(genero~data)
ggsave('plots/recapturas_total.png', g, width=ww, height=hh)
g <- ggplot(xx, aes(recapturas.periodo)) + geom_bar() + scale_y_log10() +
xlab("Periodos con un recaptura")+facet_grid(genero~data)
ggsave('plots/recapturas_periodo.png', g, width=ww, height=hh)
g <- ggplot(xx, aes(periodo.rango)) + geom_bar() + #scale_y_log10() +
xlab("Rango de los periodos")+facet_grid(genero~data)
ggsave('plots/rango_periodo.png', g, width=ww, height=hh)
g <- ggplot(xx, aes(periodo.primero, periodo.rango)) +
geom_jitter(width=.5, height=0, alpha=.5) +
xlab('Periodo de la primera captura') +
ylab("Rango de los periodos de captura") +facet_grid(genero~data)
ggsave('plots/rango_primero.png', g, width=ww, height=hh)
g <- ggplot(xx, aes(length, recapturas.periodo)) + geom_jitter(alpha=.5,
size=.1, width=0) + facet_grid(.~data)
ggsave('plots/length_vs_recapturas.png', g, width=ww, height=hh)