Boxplots for groups?

后端 未结 4 1113
再見小時候
再見小時候 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 03:54

    A solution with ggplot2.

    First, transform your data frame test to the long format using melt:

    library(reshape2)
    test.m <- melt(test)
    

    Plot the data:

    library(ggplot2)
    ggplot(test.m, aes(x = variable, y = value, fill = Type)) +
      geom_boxplot() +
      scale_fill_manual(values = c("yellow", "orange"))
    

    enter image description here

提交回复
热议问题