object cannot be coerced to type 'double' inside ggplot

#1
I am trying to use ggplot inside switch statement. providing user to select options through switch. The user enters a variable and I search my dataset based on the user input and does some operations and I will plot the resulting subset of data. But after altering my data based on user input and when using it in the ggplot command I am getting this error "object cannot be coerced to type 'double'".



switch(num,
1=={
print('You have selected option 1')

var <- as.character((readline("enter the variable name \n")))
#class(var) <- "data.frame"

gg1 <- aggregate(cbind(get(var))~Mi+hours,a, FUN=mean)
names(gg1)[3] <- var

ggplot(gg1, aes(x = hours, y = as.double(gg1[,3]), group = Mi, fill = Mi, color = Mi)) + geom_point() + geom_smooth(stat="smooth", alpha = I(0.01))

},
2=={

},
{
print('dah make your mind,look at the options again')
}
)

###########End of switch statement#########################################



The dataset is like

Ei Mi hours ABCD EFGH
1 1 1 0.1023488 0.6534707
1 1 2 0.1254325 0.5423215
1 1 3 0.1523245 0.2542354
1 2 1 0.1225425 0.2154533
1 2 2 0.1452354 0.4521255
1 2 3 0.1853324 0.2545545
2 1 1 0.1452369 0.2321542
2 1 2 0.1241241 0.2525212
2 1 3 0.0542232 0.2626214
2 2 1 0.8542154 0.2154522
2 2 2 0.0215420 0.5245125
2 2 3 0.2541254 0.2542512


This is what happening to me --

source ("filename.R")
Select any one of the options
1
[1] "You have selected option 1"
enter the variable name
ABCD
Error in eval(expr, envir, enclos) :
(list) object cannot be coerced to type 'double'
>
:shakehead