Jefftopia Jefftopia - 4 years ago 401
R Question

R: non-numeric argument to binary operator?

I'm attempting to create my first function in R. The function should take in a data frame, x-series from data frame, y-series from data frame, and plot a scatter plot. Seems simple enough, but I run into trouble when I attempt to check for an optional boolean argument.

R Script

plotScatterChart <- function(data,x,y,scale=y,line=FALSE) {

data$x <- as.numeric(x)
data$y <- as.numeric(y)

plot <- ggplot(data, aes(x, y)) +
geom_point() + # aes(alpha=0.3,color=scale)

if(line) {
plot <- plot + geom_smooth(method="lm")

ggsave(file="plot.svg", plot=plot, height=10, width=10)




non-numeric argument to binary operator


Other suggestions for improving this function are welcome.

Answer Source

The error is because of the trailing + after geom_point(). Remove that and it should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download