如何停止停止删除我的Barplot标题?

问题描述 投票:1回答:1

我想为我的数据集中的因子变量制作一个小图。为此,我一直在运行sapply(data[sapply(data, class)=='factor'],function(x) barplot(table(x)))。令我烦恼的是,这些图记住了它们的因子标签,但是没有一个保留标题。如何解决此问题而无需手动为每个图表添加标题?

当前,我得到的是像这样的含糊不清的无标题图:enter image description here

r plot apply title
1个回答
2
投票

怎么样

## extract names
fvars <- names(data)[which(sapply(data,inherits,"factor"))]
## apply barplot() with main=
lapply(fvars, function(x) barplot(table(data[[x]]), main=x))

© www.soinside.com 2019 - 2024. All rights reserved.