[R] variable in annotation, ggplot2

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Dec 16 18:27:13 CET 2019


Hello,

If you form the label with paste before the plot, it can display both 
values. Something like


lab <- paste("V = ", paste(V, collapse = ","))

ggplot(df,aes(x=x,y=y)) + geom_line() +
   annotate("text", x = 3, y = 20, label = lab)


Hope this helps,

Rui Barradas

Às 14:55 de 16/12/19, Troels Ring escreveu:
> Hi friends - I have a simple problem of inserting values in label of a
> ggplot2. I have a vector V with two values and want to show them in the
> plot.
> 
> Here is what I tried -  at most get the first entry "28".
> 
> R version 3.6.1 (2019-07-05)
> 
> Windows 10
> 
>   
> 
> BW
> Troels
> 
>   
> 
> library(ggplot2)
> 
> x <- 1:5
> 
> y <- x^2
> 
> V <- c(28,14)
> 
> df <- data.frame(x=x,y=y)
> 
> ggplot(df,aes(x=x,y=y))+geom_line()+
> 
>      annotate("text",x=3,y=20,label=bquote(V ==.(as.vector(V))))
> 
>   
> 
>   
> 
>   
> 
> ggplot(df,aes(x=x,y=y))+geom_line()+
> 
>      annotate("text",x=3,y=20,label=expression(paste("V is ",V)))
> 
>   
> 
>   
> 
> ggplot(df,aes(x=x,y=y))+geom_line()+
> 
>      annotate("text",x=3,y=20,label=bquote(V ==.(V)))
> 
> 
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smt
> p&url=/>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list