[A recent answer][1] I posted provides precisely what the OP was looking for and yet it has been downvoted, which I do not fully understand.

I reckon the question shows a clear lack of research and implementation effort and "SO is not a coding writing service" (to quote one of the comments). But at the same time, providing an answer was no trouble at all; quite the contrary, as I enjoy coding.  

Now, abstracting from this particular case, should a good answer to a bad question be downvoted?

 1. [This meta question][2] leads me to believe that most would agree bad-question-answerers should not be punished.
 2. Neither [on this meta post][3] nor [on this one][4] or [this one][5] was I able to discern a "downvote good answers" guideline. As a matter of fact, the accepted answer on the latter post advises not to.
 3. Finally, [on another post][6] the community seems to agree one should not advise on an off-topic question.

On balance, maybe I shouldn't have advised, but rather than downvoting a good answer, isn't the appropriate approach to simply downvote/flag the question and let the community/experienced users take care of it?

  [1]: https://stackoverflow.com/questions/49586766/plotting-latitude-longitude-on-map-in-r/49587100#49587100
  [2]: https://meta.stackoverflow.com/questions/252656/punish-answerers-of-bad-questions
  [3]: https://meta.stackoverflow.com/questions/254549/how-to-decide-which-questions-i-should-not-answer
  [4]: https://meta.stackoverflow.com/questions/267540/dont-answer-bad-questions
  [5]: https://meta.stackoverflow.com/questions/281793/stance-on-answering-bad-questions
  [6]: https://meta.stackoverflow.com/questions/276572/should-one-advise-on-off-topic-questions