ggplot: Boxplot of multiple column values

前端 未结 1 744
一个人的身影
一个人的身影 2020-12-05 11:51

Here is the type of data that I\'m importing as a csv file:

RPID    mm  ID  Time    Freq    Freq.1  Freq.2
RPO483  1   B6AC    5   23301   30512   
RPO483  1         


        
相关标签:
1条回答
  • 2020-12-05 12:34

    You need to reshape the data in order to plot.

    First I read your data. Note that you have some NA values.

    dat <- read.table(text = '
    RPID    mm  ID  Time    Freq    Freq.1  Freq.2
    RPO483  1   B6AC    5   23301   30512   
    RPO483  1   B6AC    25  19      17  
    RPO244  1   B6C     5   14889   20461   
    RPO244  1   B6C     25  81      86  
    RPO876  1   G3G3A   5   106760  59950   103745
    RPO876  1   G3G3A   25  4578    38119   37201
    RPO876  7   F3G3A   5   205803  148469  173580
    RPO876  7   F3G3A   25  28648   30321   26454
    RPO939  7   F3E324A 5   242285      
    RPO939  7   F3E324A 25  42837       
    RPO934  7   F3E325A 5   242001  129272  112371
    RPO934  7   F3E325A 25  73057   58685   66582',head=T, fill=T)
    

    Using reshape2 for example

    library(reshape2)
    dat.m <- melt(dat,id.vars='ID', measure.vars=c('Freq','Freq.1','Freq.2'))
    library(ggplot2)
    p <- ggplot(dat.m) +
          geom_boxplot(aes(x=ID, y=value, color=variable))
    

    enter image description here

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