R:strsplit向boxplot添加名称引发错误
题
我正在使用r中的strsplit将名称添加到boxplot,但这给了我一个错误。
strng <- "one%two%three"
tt <- strsplit(strng,"%",fixed=TRUE)
然后
boxplot(param~grp,data=snp,horizontal=TRUE,names=tt)
这会产生
ls = list(c("one", "two", :
'at' and 'labels' lengths differ, 3 != 1
Calls: boxplot ... boxplot.default -> do.call -> bxp -> do.call -> axis
Execution halted
names参数需要一个向量,strsplit返回一个列表。这些是不相容的吗?
如果我这样做
boxplot(param~grp,data=snp,horizontal=TRUE,names=c("on","two","three"))
然后就可以了。
非常感谢您的帮助
解决方案
使用方法 tt[[1]]
或 unlist(tt)
而不是 tt
boxplot(param~grp,data=snp,horizontal=TRUE,names=tt[[1]])
names
参数期望一个向量和 tt
是一个列表,所以你需要传递一个向量而不是一个列表。
不隶属于 StackOverflow