vlambda博客
学习文章列表

医学统计R语言:分面画boxplot


输入1:

setwd("C:\\Users\\mooshaa\\Desktop")
library(ggplot2)
library(foreign) 
sp <- read.spss("q.sav",to.data.frame=T,
                  use.value.lables=T,reencode='utf-8')
ggplot(sp,aes(x=newsleeptime,y=cryl,fill=newage,color=newage))+
      geom_boxplot(color="gray",alpha=0,size=0.3,fatten =4) +
      stat_boxplot(geom ='errorbar',color="gray") +
      geom_dotplot(binaxis='y'stackdir='center',binwidth =0.08)+
      geom_hline(yintercept = 3.17,lty=1,color="gray")+theme_bw()+
      facet_grid(.~newagemargins = TRUE)+
      theme(panel.grid = element_blank(),     
      strip.background=element_rect(fill="white"),
      legend.position = "none")

结果1:


前文链接: