0
votes

I have the following ggplot element stored as text:

eval(parse(text = " annotate('text', as.Date('2013-12-31'), 30.31049879  * 1.02,
       label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
       annotate('text', as.Date('2013-12-31'), 33.341548669  * 1.02,
       label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))

eval() returns error "non-numeric argument to binary operator" since it's trying to add the two parts together, but the plus sign is used differently with ggplot. Is there any way to dodge this problem?

1
What are you using the parse function for? Since you are hard coding everything, would it not be easier to just have the annotate() simply.Jrakru56
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.kkz
if that's the case, then you might be better off creating a data.frame or list to hold your x, y and 'labelJrakru56
Soemthing like this: dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))Jrakru56

1 Answers

0
votes

This was solved by putting ggplot() + at the start of the code, i.e.

eval(parse(text = "ggplot() +
annotate('text', as.Date('2013-12-31'), 30.31049879  * 1.02,
           label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
               annotate('text', as.Date('2013-12-31'), 33.341548669  * 1.02,
               label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))