# legend position help

4 messages
Open this post in threaded view
|
Report Content as Inappropriate

## legend position help

 Hi there, I draw a multiple figure in one plot, like the following: par(mfcol=c(1,5),mar=c(4,4,0,0)+0.2, oma=c(0,0,3,0)) plot(1:10, type = "b") plot(1:10, type = "b") plot(1:10, type = "b") plot(1:10, type = "b") plot(1:10, type = "b") Now, I hope to plot the legend like the following: legend("top", legend=c("Example"), pch = 21, lty = 1, merge = FALSE, horiz = TRUE, bty="n", xpd = NA) There were two problems: 1) the legend is put inside the fifth figure instead of the top center of the whole plot, i.e., the center of the outer top margin. Now, I use a stupid solution, I replace "top" in the above command with locator(1). However, using this solution, the plot have to be in an interactive mode, and the position is not accuracy. 2) the point is connected with the line in the legend. I hope there is a space between the two symbols, like --- o instead of  ---o. If possible, put the point before the line, like o ----. Unfortunately, I don't find any way to do that. Any suggestion will be greatly appreciated. Regards, Jinsong ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: legend position help

 You can use the grconvertY function to find the position in the current user coordinates that corresponds to the top of the device area (instead of using locator). Look at the "merge" argument to the legend  function. On Wed, Aug 15, 2012 at 10:04 AM, Jinsong Zhao <[hidden email]> wrote: > Hi there, > > I draw a multiple figure in one plot, like the following: > > par(mfcol=c(1,5),mar=c(4,4,0,0)+0.2, oma=c(0,0,3,0)) > plot(1:10, type = "b") > plot(1:10, type = "b") > plot(1:10, type = "b") > plot(1:10, type = "b") > plot(1:10, type = "b") > > Now, I hope to plot the legend like the following: > > legend("top", legend=c("Example"), pch = 21, lty = 1, merge = FALSE, horiz = > TRUE, bty="n", xpd = NA) > > There were two problems: > > 1) the legend is put inside the fifth figure instead of the top center of > the whole plot, i.e., the center of the outer top margin. > > Now, I use a stupid solution, I replace "top" in the above command with > locator(1). However, using this solution, the plot have to be in an > interactive mode, and the position is not accuracy. > > 2) the point is connected with the line in the legend. I hope there is a > space between the two symbols, like --- o instead of  ---o. If possible, put > the point before the line, like o ----. Unfortunately, I don't find any way > to do that. > > Any suggestion will be greatly appreciated. > > Regards, > Jinsong > > ______________________________________________ > [hidden email] mailing list > 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. [hidden email] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: legend position help

 On 2012-08-16 0:22, Greg Snow wrote: > You can use the grconvertY function to find the position in the > current user coordinates that corresponds to the top of the device > area (instead of using locator). > Thank you very much. grconvertX() and grconvertY() work very well. > Look at the "merge" argument to the legend  function. I gave "merge = FALSE" in the command. It gave the result like: ---o However, I hope to get something like: --- o or o --- (I prefer to this one) There should be a space between the point and line. Thanks again. Regards, Jinsong > > On Wed, Aug 15, 2012 at 10:04 AM, Jinsong Zhao <[hidden email]> wrote: >> Hi there, >> >> I draw a multiple figure in one plot, like the following: >> >> par(mfcol=c(1,5),mar=c(4,4,0,0)+0.2, oma=c(0,0,3,0)) >> plot(1:10, type = "b") >> plot(1:10, type = "b") >> plot(1:10, type = "b") >> plot(1:10, type = "b") >> plot(1:10, type = "b") >> >> Now, I hope to plot the legend like the following: >> >> legend("top", legend=c("Example"), pch = 21, lty = 1, merge = FALSE, horiz = >> TRUE, bty="n", xpd = NA) >> >> There were two problems: >> >> 1) the legend is put inside the fifth figure instead of the top center of >> the whole plot, i.e., the center of the outer top margin. >> >> Now, I use a stupid solution, I replace "top" in the above command with >> locator(1). However, using this solution, the plot have to be in an >> interactive mode, and the position is not accuracy. >> >> 2) the point is connected with the line in the legend. I hope there is a >> space between the two symbols, like --- o instead of  ---o. If possible, put >> the point before the line, like o ----. Unfortunately, I don't find any way >> to do that. >> >> Any suggestion will be greatly appreciated. >> >> Regards, >> Jinsong >> >> ______________________________________________ >> [hidden email] mailing list >> 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. > > > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.