I have a data frame dat that I am trying to plot with a for loop. The reason why I'm using a forloop in a function to plot ggplots is because I would like to call this function many times later.
> 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
I continue getting an error:
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
When I try calling the function like so:
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)
Any suggestions on what might be causing the error here?
aes()should exist in the data.frame you feedggplot()with.ipdRatioexists indatdataframex_val, as said in the error message.aes()? I ask this because I'm planning to create histograms with x values at different columns.