In general, in my opinion, modifying your data to use a statistical test with restrictive assumptions (in this case, no ties) is not advisable when an equivalent non-restrictive statistical method exists. Using a Spearman correlation test without an exact p-value, or using Kendall's $\tau$ in place of Spearman's $\rho$ are both valid approaches for data with ties.
As the simulation below illustrates, jittering data can induce fairly large changes in the observed p-values. Using a non-exact correlation test or Kendall's $\tau$ produce more sensible results.
x <- rnorm(1000, sd = 0.1)
x[1:100] <- x[1]
y <- x + rnorm(1000, sd = 1)
y[200:300] <- y[200]
plot(x, y)
cor.test(x, y, method = "spearman")
#> Warning in cor.test.default(x, y, method = "spearman"): Cannot compute exact p-
#> value with ties
#>
#> Spearman's rank correlation rho
#>
#> data: x and y
#> S = 152678660, p-value = 0.007922
#> alternative hypothesis: true rho is not equal to 0
#> sample estimates:
#> rho
#> 0.08392713
pvals <- replicate(1000,
cor.test(
jitter(x),
jitter(y),
method = "spearman")$p.value
)
hist(pvals, breaks = "FD")
cor.test(x, y, method = "spearman", exact = FALSE)
#>
#> Spearman's rank correlation rho
#>
#> data: x and y
#> S = 152678660, p-value = 0.007922
#> alternative hypothesis: true rho is not equal to 0
#> sample estimates:
#> rho
#> 0.08392713
cor.test(x, y, method = "kendall")
#>
#> Kendall's rank correlation tau
#>
#> data: x and y
#> z = 2.6233, p-value = 0.008709
#> alternative hypothesis: true tau is not equal to 0
#> sample estimates:
#> tau
#> 0.05590293
exact = FALSE
or instead use Kendall's tau (method = "kendall"
). $\endgroup$cor.test.default
does not calculate an exact p-value in this case. $\endgroup$