theme_sci
theme_sci<-function(){
theme(
plot.background = element_rect(fill="NA",color="NA"),
panel.background = element_rect(fill="white",colour = "black",size = 1.1),
panel.grid = element_blank(),
axis.ticks.length = unit(-0.2,"cm"),
axis.ticks=element_line(size=1),
axis.text=element_text(size=12,color="black"),
axis.text.x = element_text(margin = unit(c(0.4, 0.5, 0.2, 0.5), 'cm')),
axis.text.y = element_text(margin = unit(c(0.5, 0.4, 0.5, 0.3), 'cm')),
axis.line=element_line(color=NA),
axis.title = element_text(size=14),
axis.title.x =element_text(margin = unit(c(0.2, 0, 0.5, 0), 'cm')),
legend.key = element_rect(fill=NA,colour = NA),
legend.text=element_text(size=12),
legend.title=element_text(size=13),
legend.position = c(0.99,0.99),
legend.justification = c(0.99,0.99),
strip.text=element_text(size=20))
}
实例
library(tidyverse)
p1=iris %>%
ggplot(aes(Sepal.Length,Sepal.Width))+
geom_point(aes(color=Species))+
labs(x="Length",y="Width",title="Length~Width",color="Iris Species")
p1+theme_sci()
duncan_test
library(tidyverse)
duncan_test<-function(data,x,y){
formula1=eval(parse(text=paste0(y,"~",x)))
result1=aov(formula1,data=data)%>%agricolae::duncan.test(x)
means=result1$means%>%select(1:2)%>%as_tibble(rownames=x)
groups=result1$groups%>%select(2)%>%as_tibble(rownames=x)
means%>%inner_join(groups,by=x)
}
duncan_test(data=iris,x="Species",y="Sepal.Length")->duncan_result
ggplot(duncan_result,aes(Species,Sepal.Length))+
geom_col(fill=ggsci::pal_aaas()(1),width=0.5)+
geom_errorbar(aes(ymin=Sepal.Length-std,ymax=Sepal.Length+std),
position="dodge",width=0.3
)+
geom_text(aes(y=Sepal.Length+std,
label=groups),
vjust=-0.5,size=5
)+
theme(axis.ticks.length.x = unit(0,"mm"))+
scale_y_continuous(expand=expansion(0,0),limits=c(0,7.9))+
theme_sci()
# Duncan_test
```r
Duncan_Test<-function(data,xx,yy){
trt<- as.character(substitute(xx))
result<-aov(formula(substitute(yy~xx)),data)%>%
agricolae::duncan.test(trt)
means=result$means%>%select(1:2)%>%as_tibble(rownames=trt)
groups=result$groups%>%select(2)%>%as_tibble(rownames=trt)
means%>%left_join(groups,by=trt)
}
Duncan_Test(iris,Species,Sepal.Length)