I have a plot with a horizontal legend:
legend(\"bottomleft\", inset = c(0, -0.3), bty = \"n\",
x.intersp=0, xjust=0,yjust=0,
legend=c(\"AAP
For my case, there were 5 legends in horizontal way. I have to customize the spacing between each legend. Following was the code snippet for this purpose.
legend("topright",horiz = T, legend = df2, fill = col_box,
inset = c(-0.2,-0.1), xpd = TRUE, bty = 'n', density = density_value, angle = angle_value, x.intersp=0.3,
text.width=c(3.5,3.4,3.7,4.3,7))
It was the text.width
function that do the magic