How to generate boxplot

后端 未结 3 1306
-上瘾入骨i
-上瘾入骨i 2020-12-12 01:59

I have a data and from that, I want to generate boxplot. My file is saved in \"1.txt\" file and it seems like this

R  S1G1   S1G2   S2G1   S2G2
1  0.98   0.9         


        
相关标签:
3条回答
  • 2020-12-12 02:26

    Maybe you want to reshape your data first:

    x1 <- reshape(x, idvar="R", varying=list(2:5), direction="long")
    

    And than plot it:

    boxplot(S1G1 ~ R, data=x1, main = "Output result",las = 2, pch=16, cex = 1,
        col = "lightblue", xlab = "R",ylab = "SNP values",ylim =c(-0.4,1.2), 
        border ="blue", boxwex = 0.3)
    

    boxplot

    0 讨论(0)
  • 2020-12-12 02:33

    Your comments are a little tough to decipher, but I'm guessing that maybe you wanted a boxplot for each column S1G1, etc. In that case I'd melt your data:

    xx <- read.table(textConnection("R  S1G1   S1G2   S2G1   S2G2
    1  0.98   0.98   0.96   0.89
    2  0.89   0.89   0.98   0.88
    3  0.88   0.99   0.89   0.87"),header = TRUE, sep ="")
    
    xx1 <- melt(xx, id.vars = "R")
    

    and then you can make side-by-side boxplots using any of the popular graphing idioms:

    ggplot(xx1, aes(x = variable, y = value)) + 
        geom_boxplot()
    

    enter image description here

    Or you can use base graphics or lattice (plots omitted):

    boxplot(value~variable, data = xx1)
    
    bwplot(value~variable,data = xx1)
    
    0 讨论(0)
  • 2020-12-12 02:44

    After reading this post i found my solution to be sticking the table in data.frame(). Using the above example:

    Xtab <- data.frame(x)
    boxplot(Xtab$Freq ~ Xtab$Var1)
    
    0 讨论(0)
提交回复
热议问题