[R] Separating point symbols and line types in a legend.

Greg Snow 538280 at gmail.com
Fri Feb 12 21:22:42 CET 2016


One option is to call `legend` twice and do some manual positioning.
This worked for me:

plot(1:10)
legend('topleft', lty=1:3, bty="n", legend=c('','','') )
legend('topleft', pch=c(20,8,1), bty="n",
legend=c('clyde','irving','melvin'), inset=c(0.1,0))

You may need to fiddle with the amount of inset for your particular
plot and device combination.



On Thu, Feb 11, 2016 at 9:52 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>
> I would like to have a legend given in the manner
>
> legend("topleft",pch=c(20,8,1),lty=1:3,bty="n",
>        legend=c("clyde","irving","melvin"))
>
> but with the point symbol *NOT* being superimposed on the line segments that
> are plotted.
>
> I saw that I can specify "merge=FALSE" in the call to legend() but this
> gives results like unto
>
>    ----* irving
>
> with the plot symbol being immediately juxtaposed to the plotted line
> segment.  I would like a space between them, like so:
>
>    ---- * irving
>
> (See the difference?)
>
> I can see no arguments to legend that allow me to effect this.  I can adjust
> positioning of the legend text, but not of the plotted point character or
> line segment.  Is there any way to effect the desired result?  Or is there a
> "simple" adjustment that one could make to the code for legend() that would
> allow me to accomplish what I want?
>
> Ta.
>
> cheers,
>
> Rolf Turner
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> R-help at 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list