ggplot2, geom_boxplot with custom quantiles and outliers

后端 未结 1 516
萌比男神i
萌比男神i 2021-02-09 03:46

I have a dataset which includes data from 100 simulations of train runs in a network with 4 trains, 6 stations and lateness at arrival for each train at each station. My data lo

1条回答
  •  失恋的感觉
    2021-02-09 04:13

    This?

    ggplot(MyData, aes(factor(Stations), Arrival_Lateness, 
                       fill = factor(Train_number))) + 
      stat_summary(fun.data = f, geom="boxplot", 
                   position=position_dodge(1))+
      stat_summary(aes(color=factor(Train_number)),fun.y = q, geom="point", 
                   position=position_dodge(1))
    

    IMHO this is a little easier to interpret.

    ggplot(MyData, aes(factor(Train_number), Arrival_Lateness, 
                   fill = factor(Train_number))) + 
      stat_summary(fun.data = f, geom="boxplot",
                   position=position_dodge(1))+
      stat_summary(aes(color=factor(Train_number)),fun.y = q, geom="point", 
                   position=position_dodge(1))+
      facet_grid(.~Stations, scales="free")+
      theme(axis.text.x=element_text(angle=-90,hjust=1,vjust=0.2))+
      labs(x="Train Number")
    

    EDIT (Response to OP's comment)

    ggplot(MyData, aes(factor(Train_number), Arrival_Lateness, 
                       fill = factor(Train_number))) + 
      stat_summary(fun.data = f, geom="boxplot",
                   position=position_dodge(1))+
      stat_summary(aes(color=factor(Train_number)),fun.y = q, geom="point", 
                   position=position_dodge(1))+
      facet_grid(.~Stations, scales="free")+
      theme(axis.text.x=element_blank(), axis.ticks.x=element_blank())+
      scale_fill_discrete("Train")+scale_color_discrete("Train")+
      labs(x="")
    

    To turn off x-axis text and tick marks, us theme(...=element_blank()). To turn off the axis label, use labs(x=""). Also, the fill and color scales have to have the same name, or they display separately.

    0 讨论(0)
提交回复
热议问题