[R] legend: interplay between title and y.intersp

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sat Mar 4 17:59:26 CET 2023


Set the legend position explicitly with x and y values and add xpd = TRUE
to the legend call to clip the plot to the figure region and not the plot
region (the default). Something like this (you may have to fool around with
y.intersp, etc. to allow enough space between the legend lines):

plot(c(0,1), c(0,1), type="n")

legend(x = .4, y = 1.25, legend=c("", "", "a"), col=c("blue", "red",
"green"), xpd = TRUE, lty = 1, y.intersp= .75, title = 'test')

Cheers,
Bert

Cheers,
Bert


On Sat, Mar 4, 2023 at 7:45 AM Sigbert Klinke <sigbert using wiwi.hu-berlin.de>
wrote:

> Hi,
>
> my MWE is not working as expected:
>
> plot(c(0,1), c(0,1), type="n")
>
> legend("top", legend=c("", "", "a"), col=c("blue", "red", "green"),
> title="test", y.intersp=0.2, lwd=1)
>
> The lines are not below the title. I want (nearby) lines as in the plot,
> but below the title. Is there a way to achieve this?
>
> Thanks Sigbert
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list