I have a linebreak in a legend in R and my problem is that the graphic looks not as expected.
My minimal example is as follows:
plot(1)
legendLabel<-c("t\nu ","tu","wh","trr\nni")
legend("top",legend=legendLabel,horiz=TRUE,fill=c("red","blue","gray","black"))
I would expect that the upper and lower margin of the legend is equal, but this is not the case.
As you can see in the attached image, the lower margin is smaller then the upper.
Does anybody have an idea how to fix it or can anyone tell me what the problem is?
Thanks.
Thanks to @’Marc in the box’ I found a good working solution.
Disable the box as he told with
bty="n"and thenSo I first calculated the distance between the top corner and the dataPoint and afterwords draw with this information a polygon.
Works quite general has far as I have seen.
Thanks.