Select the suitable neighborhood size for Isomap function

I´m working with a Distance Matrix that I want to represent on a 2D plane using Isomap and one of the inputs is the parameter K (k Nearest Neighbors). I've seen that it´s possible to determine the suitable K value plotting the residual variance or the least-squares error versus the different neighborhood sizes, but I'm having trouble finding a way to do it. Is there any package that can do those computations?