-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirst_observations.Rmd
176 lines (133 loc) · 4.19 KB
/
first_observations.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
title: "Trials Population VEF"
output:
html_document:
toc: true
toc_float: true
df_print: paged
---
## Description
Below is a description of the VEF population (Vivero equipo frijol), which has information from 2013 to 2014.
----
## Dataset Global
```{r , echo=FALSE, warning=FALSE,message=FALSE}
library(plotly)
library(ggplot2)
library(dplyr)
library(RColorBrewer)
```
```{r rows.print=5,echo=FALSE}
file <- "D:/APARICIO JOHAN/CGIAR/Ariza, Daniel (CIAT) - Johan/VEF_raw_data/all_merged_to_send.csv"
#file <- "C:/Users/johan/CGIAR/Ariza, Daniel (CIAT) - Johan_Aparicio/VEF_raw_data/all_merged_to_send.csv"
Data <- read.csv(file)
head(Data)
```
<br>
The notation used for each trial is given by:
$$Pal14C\_drt$$
1. the location where the trial was conducted
1. the year in which it took place
1. the quarter of the year
1. the conditions or stress to which the test was submitted
<br>
<br>
<center>
```{r , echo=FALSE, warning=FALSE,message=FALSE, rows.print=12}
Data %>% group_by(dataset) %>%
summarise(Number_Gen=n_distinct(line),
Number_Rep=n_distinct(rep),
Number_Block=n_distinct(block)) -> Gen
Gen
```
</center>
<br>
<center>
```{r, echo=FALSE, warning=FALSE,message=FALSE}
library(dplyr)
library(reshape)
introduced <- function(datosVEF){
k <- list()
for (i in 1:nlevels(datosVEF$dataset)) {
k[[i]] <- droplevels(datosVEF$line[datosVEF$dataset==levels(datosVEF$dataset)[i]])
names(k)[i] <- levels(datosVEF$dataset)[i]
}
Datasets <- nlevels(datosVEF$dataset)
Line_GL <- levels(datosVEF$line)
Binary <- matrix(NA,nrow = length(Line_GL), ncol = Datasets )
# Matriz Binaria
for (i in 1:Datasets) {
Binary[,i] <- ifelse(Line_GL%in%k[[i]], 1 , 0)
}
colnames(Binary) <- names(k)
rownames(Binary) <- Line_GL
# Ordenar por a?o
Binary <- Binary[,c(4:9,1,3,10,11,12)]
Trials <- 11
# Nuevo Orden
Order_K <- c(k[4:9],k[1],k[3],k[10:12])
# Codigo-----------------------------------
w <- matrix(NA,Trials,Trials)
for (i in 1:(Trials-1)) {
for (j in 1:(Trials-1)) {
w[i+1,j] <- length(Reduce(intersect, Order_K[j:(i+1)]))
}
}
diag(w) <- colSums(Binary)[1:Trials]
for (i in Trials:2) {
w[,i] <- w[,i]-w[,i-1]
}
for (i in 1:(Trials-1)) {
for (j in 1:(Trials-1)) {
if (j>i) {
w[i,j] <- 0
}
}
}
#----------------------------------------
# Matriz
rownames(w) <- colnames(Binary)
colnames(w) <- colnames(Binary)
w <- melt(w)
w$value <- ifelse(w$value==0,NA,w$value)
w$X2 <- factor(w$X2, levels = rev(levels(w$X2)) )
names(w) <- c("Trial", "Introduced","Freq")
w %>% filter(Freq > 3) -> w
# GGPLOT
library(RColorBrewer)
library(ggplot2)
p <- ggplot(w, aes(x = Trial, y = Freq,fill=Introduced, label = Freq)) +
geom_bar(stat = "identity", colour="black") +
guides(fill=guide_legend(reverse = TRUE))+
geom_text(size = 3, position = position_stack(vjust = 0.5))+theme_bw(base_size = 13)+
theme(legend.position="top",axis.text.x = element_text(angle = 90, hjust = 1))+ ylab("Number of Lines")+
scale_fill_manual(values = rev(brewer.pal(7,"Pastel1")))+
scale_x_discrete(limits=c("Pal13C_drt", "Pal14A_irr", "Pal14C_drt", "Pal15C_drt", "Pal15C_irr",
"Pal16C_drt","Dar16C_hiP" ,"Dar16C_mdP", "Pal17C_drt", "Pal18A_irr" ,
"Pal18C_drt"))
return(p)
}
datosVEF <- read.csv(file = file)
ggplotly(introduced(datosVEF))
```
</center>
<br>
<center>
```{r , echo=FALSE, warning=FALSE,message=FALSE }
k <- brewer.pal(12,"Set3")
k[9] <- "#CD534CFF" ; k[12] <- "#CD534CFF"
Data %>%
group_by(dataset) %>%
summarise(Total=n()) -> conteo
g <- ggplot(conteo, aes(dataset,y=Total, fill=dataset,label=Total))+
geom_bar(stat = "identity", colour="black") +
guides(fill=guide_legend(reverse = TRUE))+
geom_text(size = 3, position = position_stack(vjust = 0.5))+theme_bw(base_size = 13)+
scale_x_discrete(limits=c("Pal13C_drt", "Pal14A_irr", "Pal14C_drt", "Pal15C_drt", "Pal15C_irr",
"Pal16C_drt","Dar16C_hiP" ,"Dar16C_mdP", "Dar16C_loP" , "Pal17C_drt", "Pal18A_irr" ,"Pal18C_drt"))+
scale_fill_manual(values = k )+
theme(legend.position="top",axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g)
```
</center>
## End
----