"can put a line and plot function under an if statement. ...? It works when I try it ..."
It would seem you've answered your own question.
Whatever code that needs to be in whatever section of an if...[[elseif]..else]...end block is fine inside whichever clause it needs to be in to satisfy the logic needs of the program.
I can't think of anything other than not fully containing another block construct like a for...end block fully within a clause that couldn't be inside whatever part of the construct you wanted it.
If it were "after the end", then it would no longer be part of the conditional construct and thus be executed always; obviously not a satisfactory solution if it is only to draw the line sometimes and not other times.