GGplot overriding theme functions

For some reason the ggplotly call overrides most, but not all of my theme elements. It ends up overriding the legend in specific, which is frustrating considering that I always alter the position and justification thereof. Furthermore, in this specific case I use two geom_line() to specify a second aes for a second vector of my dataframe and use scale_colour_distinct to specify the line types and add the second vector to the legend.

Lastly, while the plot renders correctly in viewer mode when I specify the margin sizes, it does not respect the margin when it renders in a markdown document. In specific it continues to cut off the y-axis label nor does it observe my axis tick element settings in my theme function