我有一个数据帧dat
,我试图用for循环绘图。我之所以在一个函数中使用forloop来绘制ggplots,是因为我想在后面多次调用这个函数。R ggplot for循环变数
> head(dat)
tpl motif strand base score ipdRatio
1: 24501 AAGTACTCG 0 A 51 3.108
2: 58809 GAGTACTAC 0 A 69 4.095
3: 65614 TAGTACTCA 0 A 61 3.341
4: 78494 GAGTACTAC 0 A 92 4.968
5: 92127 AAGTACTTA 0 A 23 1.702
6: 193102 GAGTACTCG 0 A 96 5.255
我不断收到一个错误:
Error in eval(as.symbol(x_val)) : error in evaluating the argument 'expr' in selecting a method for function 'eval': Error in as.symbol(x_val) : object 'x_val' not found
当我尝试调用像这样的功能:
plotme <- function(dataf,x_val,bin_width){
print(ggplot(dataf, aes(x = eval(as.symbol(x_val)))) +
geom_histogram(binwidth = bin_width))
}
ratioplot <- plotme(dat,"ipdRatio",.5)
什么可能会在这里造成错误有什么建议?
任何你把里面的'AES()'应在data.frame存在你喂'ggplot()'用。 –
,但'dat'数据框中存在'ipdRatio'列。 – ALKI
但不是'x_val',如错误消息中所述。 –