【发布时间】:2018-12-09 15:16:08
【问题描述】:
我想编写一个R 函数,它读取文件m,并使用ggplots2 绘制箱线图。
这是函数:
stringplotter = function(m, n) {
library(ggplot2)
require(scales)
data<-as.data.frame(read.table(file=m, header=T, dec=".", sep="\t"))
ggplot(data, aes(x=string, y=n)) + geom_boxplot() + geom_point() + scale_y_continuous(labels=comma)
}
一个示例文件test:
C string
97 ccc
95.2 ccc
88.6 nnn
0.5 aaa
86.4 nnn
0 ccc
85 nnn
73.9 nnn
87.9 ccc
71.7 nnn
94 aaa
76.6 ccc
44.4 ccc
92 aaa
91.2 ccc
当我调用函数时
stringplotter("test", C)
我得到了错误
Fehler: Column `y` must be a 1d atomic vector or a list
Call `rlang::last_error()` to see a backtrace
当我直接调用函数内部的命令时,一切都按预期工作。我的错误在哪里?
【问题讨论】: