sp1<-c(22,34,26,24,30)
sp2<-c(35,43,44,29,38)
sp3<-c(45,54,39,55,49)
sp4<-c(33,35,36,37,42)
dados<-data.frame(sp1,sp2,sp3,sp4)
dat<-stack(dados)
anova = aov(dat$values~dat$ind)
tk_teste <- TukeyHSD(anova)
plot(tk_teste, col="black", cex.axis=0.75)
setwd("G:/Meu Drive/R")
library(readxl)
testeanv<-read_xlsx("testeanova.exemplo.xlsx")
testeanv
## # A tibble: 20 Ă 2
## Valores Locais
## <dbl> <chr>
## 1 22 L1
## 2 34 L1
## 3 26 L1
## 4 24 L1
## 5 30 L1
## 6 35 L2
## 7 43 L2
## 8 44 L2
## 9 29 L2
## 10 38 L2
## 11 45 L3
## 12 54 L3
## 13 39 L3
## 14 55 L3
## 15 49 L3
## 16 33 L4
## 17 35 L4
## 18 36 L4
## 19 37 L4
## 20 42 L4
ANOVA<-aov(testeanv$Valores~testeanv$Locais)
summary(ANOVA)
## Df Sum Sq Mean Sq F value Pr(>F)
## testeanv$Locais 3 1129 376.3 12.98 0.000149 ***
## Residuals 16 464 29.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TUKEY<-TukeyHSD(ANOVA)
TUKEY
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = testeanv$Valores ~ testeanv$Locais)
##
## $`testeanv$Locais`
## diff lwr upr p adj
## L2-L1 10.6 0.8557176 20.344282 0.0306731
## L3-L1 21.2 11.4557176 30.944282 0.0000653
## L4-L1 9.4 -0.3442824 19.144282 0.0606123
## L3-L2 10.6 0.8557176 20.344282 0.0306731
## L4-L2 -1.2 -10.9442824 8.544282 0.9844430
## L4-L3 -11.8 -21.5442824 -2.055718 0.0151889
GGTukey<-function(Tukey){
A<-require("tidyverse")
if(A==TRUE){
library(tidyverse)
} else {
install.packages("tidyverse")
library(tidyverse)
}
B<-as.data.frame(Tukey[1])
colnames(B)[2:3]<-c("min",
"max")
C<-data.frame(id=row.names(B),
min=B$min,
max=B$max)
D<-C%>%
ggplot(aes(id))+
geom_errorbar(aes(ymin=min,
ymax=max),
width = 0.2)+
geom_hline(yintercept=0,
color="red")+
labs(x=NULL)+
coord_flip()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="grey75"),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.59),
legend.key= element_rect(color="white",fill="white")
)
return(D)
}
GGTukey(TUKEY)
## Carregando pacotes exigidos: tidyverse
## ââ Attaching packages âââââââââââââââââââââââââââââââââââââââ tidyverse 1.3.1 ââ
## â ggplot2 3.3.6 â purrr 0.3.4
## â tibble 3.1.6 â dplyr 1.0.9
## â tidyr 1.2.0 â stringr 1.4.0
## â readr 2.1.2 â forcats 0.5.1
## ââ Conflicts ââââââââââââââââââââââââââââââââââââââââââ tidyverse_conflicts() ââ
## â dplyr::filter() masks stats::filter()
## â dplyr::lag() masks stats::lag()
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
GGTukey.2<-function(Tukey){
A<-require("tidyverse")
if(A==TRUE){
library(tidyverse)
} else {
install.packages("tidyverse")
library(tidyverse)
}
B<-as.data.frame(Tukey[1])
colnames(B)[2:4]<-c("min",
"max",
"p")
C<-data.frame(id=row.names(B),
min=B$min,
max=B$max,
idt=ifelse(B$p<0.05,
"significant",
"not significant")
)
D<-C%>%
ggplot(aes(id,color=idt))+
geom_errorbar(aes(ymin=min,
ymax=max),
width = 0.5,
size=1.25)+
labs(x=NULL,
color=NULL)+
scale_color_manual(values=c("red",
"green")
)+
coord_flip()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="grey75"),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.59),
legend.key= element_rect(color="white",fill="white")
)
return(D)
}
GGTukey.2(TUKEY)
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
GGTukey.3<-function(Tukey, Style){
GT<-function(Tukey){
A<-require("tidyverse")
if(A==TRUE){
library(tidyverse)
} else {
install.packages("tidyverse")
library(tidyverse)
}
B<-as.data.frame(Tukey[1])
colnames(B)[2:3]<-c("min",
"max")
C<-data.frame(id=row.names(B),
min=B$min,
max=B$max)
D<-C%>%
ggplot(aes(id))+
geom_errorbar(aes(ymin=min,
ymax=max),
width = 0.2)+
geom_hline(yintercept=0,
color="red")+
labs(x=NULL)+
coord_flip()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="grey75"),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.59),
legend.key= element_rect(color="white",fill="white")
)
return(D)
}
GT2<-function(Tukey){
A<-require("tidyverse")
if(A==TRUE){
library(tidyverse)
} else {
install.packages("tidyverse")
library(tidyverse)
}
B<-as.data.frame(Tukey[1])
colnames(B)[2:4]<-c("min",
"max",
"p")
C<-data.frame(id=row.names(B),
min=B$min,
max=B$max,
idt=ifelse(B$p<0.05,
"significant",
"not significant")
)
D<-C%>%
ggplot(aes(id,color=idt))+
geom_errorbar(aes(ymin=min,
ymax=max),
width = 0.5,
size=1.25)+
labs(x=NULL,
color=NULL)+
scale_color_manual(values=c("red",
"green")
)+
coord_flip()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="grey75"),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.59),
legend.key= element_rect(color="white",fill="white")
)
return(D)
}
GR<-if(Style==1){
return(GT(Tukey))
} else if(Style==2){
return(GT2(Tukey))
}
return(GR)
}
GGTukey.3(TUKEY,Style=1)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
GGTukey.3(TUKEY,Style=2)
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database