Optimal defensive investments in plants