0

I want to print in a plot the correlation between pred x obs, the RMSE and Rsquared. When I calculate using "postResample", I get both values together, but I want them separated. So when I ask R to plot, it plots everything together. Could somebody help plotting it separated?

## Ploting residuals
axisRange <- extendrange(c(observed, predicted))
plot(observed, predicted,
 ylim = axisRange,
 xlim = axisRange,
 ylab = 'Predicted',
 xlab = 'Observed', las=1)

 ## correlation predicted x observed
 inform = as.character(round(cor(predicted, observed), digits = 2))
 text(x=10,y=46, paste('Corr =', inform))
 text(x=10,y=43, paste('RMSE =', inform))
 text(x=10,y=40, paste('RSquared =', inform))

 ## Adding reference line
 abline(0, 1, col = "darkgrey", lty = 2)

 ## Calculating Rsquared and RMSE
 postResample(predicted, observed)
Julian Wittische
  • 1,219
  • 14
  • 22
Murillo
  • 1
  • 2
  • 1
    You need to provide an example; read this: [How to make a great reproducible example in R?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – M-- Jun 05 '17 at 20:33

1 Answers1

0

You can use the [] to access the first (RMSE) and the second (R squared) elements of the output of the function postResample().

Here is an example:

postResample(1:10,9:18)[1]

postResample(1:10,9:18)[2]

So in your code:

## Ploting residues
axisRange <- extendrange(c(observed, predicted))
plot(observed, predicted,
 ylim = axisRange,
 xlim = axisRange,
 ylab = 'Predicted',
 xlab = 'Observed', las=1)

 ## correlation predicted x observed
 inform = as.character(round(cor(predicted, observed), digits = 2))
 text(x=10,y=46, paste('Corr =', inform))
 text(x=10,y=43, paste('RMSE =', postResample(predicted, observed)[1]))
 text(x=10,y=40, paste('RSquared =', postResample(predicted, observed)[2]))

 ## Adding reference line
 abline(0, 1, col = "darkgrey", lty = 2)
Julian Wittische
  • 1,219
  • 14
  • 22