This is definitely possible, but I don't have time to provide a full
answer. At least you could use JavaScript to change <img> to a link
<a> and add a click event on it to achieve what you wanted; or set a
knitr plot hook to generate the expected <a>:
https://bookdown.org/yihui/rmarkdown-cookbook/output-hooks.html
I'd recommend that you try other forums such as Stack Overflow or
RStudio Community. This mailing list has not really been active for a
few years...
Regards,
Yihui
--
https://yihui.org