Boxplots for groups?

后端 未结 4 1109
再見小時候
再見小時候 2020-12-30 03:31

I have a dataset (test) as given below:

Type    Met1    Met2    Met3    Met4
TypeA   65  43  97  77
TypeA   46  25  76  77
TypeA   44  23  55  46
TypeA   46          


        
4条回答
  •  借酒劲吻你
    2020-12-30 04:07

    like this,

    test <- structure(list(Type = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 
        2L, 2L, 2L), .Label = c("TypeA", "TypeB"), class = "factor"), 
        Met1 = c(65L, 46L, 44L, 46L, 33L, 66L, 55L, 55L, 36L, 67L
        ), Met2 = c(43L, 25L, 23L, 44L, 22L, 8L, 76L, 77L, 67L, 55L
        ), Met3 = c(97L, 76L, 55L, 55L, 55L, 66L, 66L, 88L, 55L, 
        76L), Met4 = c(77L, 77L, 46L, 77L, 54L, 47L, 65L, 46L, 44L, 
        65L)), .Names = c("Type", "Met1", "Met2", "Met3", "Met4"), 
        class = "data.frame", row.names = c(NA, -10L))
    
    
    # install.packages("ggplot2", dependencies = TRUE)
    require(ggplot2)
    require(reshape2)
    df <- melt(test)
    p <- ggplot(df, aes(factor(variable), value)) + geom_boxplot(aes(fill = Type))
    p
    

    enter image description here

    You take a look at the geom_boxplot manual page.

提交回复
热议问题