2017-09-07 4 views
0

J'utilise le support plotmath en ajoutant des annotations à mon intrigue, c'est-à-dire en utilisant l'argument parse=TRUE. En examinant le plotmath documentation here, il n'est pas clair comment échapper des symboles prédéfinis, par ex. %Comment échapper des symboles prédéfinis, par ex. % avec plotmath?

label <- 'atop(This~goes~on~top,of~this~with~11.1%)' # how to escape the % sign? 
geom_text(...,label=label,parse=TRUE) 

qui conduit à l'erreur suivante:

Error in parse(text = as.character(lab)) : <text>:1:40: unexpected input 
1: atop(This~goes~on~top,of~this~with~11.1%) 
             ^
+1

S'il vous plaît fournir un [ exemple reproductible] (https://stackoverflow.com/q/5963269/980833). –

Répondre

1

Il suffit de mettre entre guillemets

label <- 'atop(This~goes~on~top,of~this~with~"11.1%")' 
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + 
    annotate("text", x = 4, y = 25, label = label, parse=TRUE) 

Il suffit de mettre tous les tests dans les citations

label <- 'atop("This goes on top of this with 11.1%")' 
+0

Parfait cela fonctionne! Je vous remercie! –