I'm generating some graphs in markdown file, but the graph does not look right in the html file.
In RStudio, it works well, and looks like this:
But in the markdown html file, the legend box on the right side is cut off:
I tried adjusting fig.width
, fig.align
, fig.show='asis'
, fig.crop
. They either didn't make any change, or just made the figure as a whole look narrower with the legend box still being incomplete.
Is there any way to make it look normal in markdown html file?
I had this issue too in Rmarkdown html reports, I solved it by changing the plot margins in ggplot2: theme(plot.margin=unit(c(1,2,1,1),"cm")). The second 'unit' number was increased from 1 to 2 to allow for the legend on the right. I found this answer here: ggplot2: Exclude legend from aspect ratio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With