我的函数代码

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)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值