-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
51 lines (37 loc) · 1.54 KB
/
server.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
library(ggplot2)
library(reshape)
library(RColorBrewer)
# Define server logic required to draw a histogram ----
shinyServer (function(input, output, session) {
output$distPlot <- reactivePlot(function(){
genetic.drift <- function(N = input$N, p = input$p, N.gen = input$N.gen, N.sim = input$N.sim){
# Set up parameters
N.chrom = 2*N # number of chromosomes
q = 1-p
# Simulation
P = array(0, dim=c(N.gen,N.sim))
P[1,] = rep(N.chrom*p,N.sim) # initialize number of A1 alleles in first generation
for(j in 1:N.sim){
for(i in 2:N.gen){
P[i,j] = rbinom(1,N.chrom,prob=P[i-1,j]/N.chrom)
}
}
P = data.frame(P/N.chrom)
# Reshape data and plot the 5 simulations
sim_data <- melt(P)
gd <- ggplot(sim_data, aes(x = rep(c(1:N.gen), N.sim), y = value, group = variable)) +
geom_line(aes(colour = variable),size=0.9) +
scale_colour_manual(values = colorRampPalette(brewer.pal(N.sim,("Set2")))(N.sim)) +
labs(title = "Efeitos da Deriva Genética em frequências alélicas ", subtitle= "Organismos diplóides") +
xlab("Gerações") +
ylab("Frequência Alélica") +
ylim(0,1) +
labs(colour = "Alelos") +
theme(text = element_text(color = "grey20", size=14),
plot.title=element_text(size=18),
legend.text=element_text(size=14))
print(gd)
}
genetic.drift(input$N, input$p, input$N.gen, input$N.sim)
})
})