简体   繁体   中英

Concatenate strings and results in R plotmath

In R, I want to include a legend in a plot with the result of the Spearman's rho. I use this:

expression(paste(rho, " = ", cor(v$V1, v$V2, method = 'spearman')))

But in the legend I get:

p = cor($(v,V1), $(v,V2), spearman)

How can I get the result of cor?

Here's an example that should help:

set.seed(42)
x <- 1:10
y <- rnorm(10)
plot(x,y)
text(7,1, bquote(rho==.(cor(x,y, method="spearman"))))

在此输入图像描述

?bquote explains that it'll evaluate calls within .() . You generally don't need to use paste within plotmath .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM