使用lapply制作变量列表的箱形图 [英] Using lapply to make boxplots of a variable list

查看:61
本文介绍了使用lapply制作变量列表的箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的数据集中使用这种类型的箱形图来表示多个y变量:所有箱形图的正常箱形图物种为x值的虹膜.由于我要绘制多个y变量,因此我尝试像这样使用lapply:

I want this type of boxplot for several y-variables in my dataset: normal boxplot for all irises with Species as x-value. Since I have multiple y variables to plot, I tried to use lapply like this:

varlist <- c('Sepal.Length', 'Sepal.Width')

plot <- function (varlist) {
  require(ggplot2)
  ggplot(data = iris, aes(x=Species, y=varlist))+
    geom_boxplot() 
}

lapply(varlist, FUN = plot)

我得到了这个情节:每个情节只有一个虹膜

如何使用循环类型(由于有多个y值)来获得普通的箱形图,并且其中所有由x变量分组的虹膜都包含在框中?

How can I get normal boxplots using a type of loop (because of several y-values), and where all irises grouped by the x-variable are included in the boxes?

推荐答案

IIRC, aes()不处理字符串输入;您需要 aes_string().我希望(但未经测试)如果将 ggplot()调用更改为 ggplot(data = iris,mapping = aes_string(x ='Species',y =varlist)).

IIRC, aes() does not handle string inputs; you need aes_string(). I expect (but have not tested) that your function will work if you change you ggplot() call to ggplot(data = iris, mapping = aes_string(x = 'Species', y = varlist)).

这篇关于使用lapply制作变量列表的箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆