Using example given on this page: ggplot inside function not working despite deparse(substitute , I tried to use aes_string but it is not working:
testfn <- function(gdf, first, second, third, fourth){
print(
ggplot(gdf, aes_string(first, second,
color = fourth,
linetype = third,
group = third:fourth))+
geom_point()+
geom_line()
)
}
>
> testfn(phil, "Level", "value","Gender","Name")
Error in third:fourth : NA/NaN argument
In addition: Warning messages:
1: In aes_string(first, second, color = fourth, linetype = third, group = third:fourth) :
NAs introduced by coercion
2: In aes_string(first, second, color = fourth, linetype = third, group = third:fourth) :
NAs introduced by coercion
>
Where is the problem. Thanks for your help.