Re: [R] Legend position in ggplot

2021-06-17 Thread Felipe Carrillo via R-help
Like this? theme(legend.position= 'top'


On Thursday, June 17, 2021, 10:52:04 AM PDT, peri He 
 wrote:  
 
 Dear Friends,

I would like to see my legend outside of a ggplot (at the top).

This code is showing the legend inside of a plot:
theme(legend.position=c(0.15,0.97))

But when I changed it to : theme(legend.position=c(-0.15,1.5)) , the legend 
disappears.

I would appreciate it if you share your ideas.

Regards,

Peri



    [[alternative HTML version deleted]]

__
R-help@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]]

__
R-help@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.


[R] Legend position in ggplot

2021-06-17 Thread peri He
Dear Friends,

I would like to see my legend outside of a ggplot (at the top).

This code is showing the legend inside of a plot:
theme(legend.position=c(0.15,0.97))

But when I changed it to : theme(legend.position=c(-0.15,1.5)) , the legend 
disappears.

I would appreciate it if you share your ideas.

Regards,

Peri



[[alternative HTML version deleted]]

__
R-help@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.


[R] legend position

2013-12-02 Thread philippe massicotte
Hi all. 
I'm ploting a raster and I can't find the proper way to move the legend. For 
example,
r = raster(system.file(external/test.grd, package=raster))plot(r)
How can I put the legend at the desired position?
Thank in advance,Phil 
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] legend position

2013-12-02 Thread Carl Witthoft
See ?legend .   you can add a legend directly to an existing plot.  An
example:

legend('topright',c('hot','cold'),lty=1,col=c('red','green'),bg='white')

Now if you're trying to place the legend outside the plot area (i.e. in some
other part of the window),
you'll need to invoke par(xpd=TRUE) . See the help at ?par .


Filoche wrote
 Hi all. 
 I'm ploting a raster and I can't find the proper way to move the legend.
 For example,
 r = raster(system.file(external/test.grd, package=raster))plot(r)
 How can I put the legend at the desired position?
 Thank in advance,Phil   
   [[alternative HTML version deleted]]
 
 __

 R-help@

  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.





--
View this message in context: 
http://r.789695.n4.nabble.com/legend-position-tp4681489p4681492.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] legend position

2013-12-02 Thread philippe massicotte
Thank you for reply.
If I'm not wrong, legend(...) will works for discrete elements.  I'm not sure 
hot to use it for a colorbar legend sur as the one in the example bellow.
Phil
 Date: Mon, 2 Dec 2013 11:49:19 -0800
 From: c...@witthoft.com
 To: r-help@r-project.org
 Subject: Re: [R] legend position
 
 See ?legend .   you can add a legend directly to an existing plot.  An
 example:
 
 legend('topright',c('hot','cold'),lty=1,col=c('red','green'),bg='white')
 
 Now if you're trying to place the legend outside the plot area (i.e. in some
 other part of the window),
 you'll need to invoke par(xpd=TRUE) . See the help at ?par .
 
 
 Filoche wrote
  Hi all. 
  I'm ploting a raster and I can't find the proper way to move the legend.
  For example,
  r = raster(system.file(external/test.grd, package=raster))plot(r)
  How can I put the legend at the desired position?
  Thank in advance,Phil 
  [[alternative HTML version deleted]]
  
  __
 
  R-help@
 
   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.
 
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/legend-position-tp4681489p4681492.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org 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.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] legend position

2013-12-02 Thread Carl Witthoft
It occurs to me that perhaps you're referring to the 'color bar' on the right
of the plot.  AFAIK you cannot get at that from the raster::plot method.  
However  lattice::levelplot does allow you to manipulate or remove that
colorbar.




--
View this message in context: 
http://r.789695.n4.nabble.com/legend-position-tp4681489p4681497.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] legend position

2013-12-02 Thread philippe massicotte
Thank you, I'll try to work with lattice.
Regards,Phil

 Date: Mon, 2 Dec 2013 12:06:50 -0800
 From: c...@witthoft.com
 To: r-help@r-project.org
 Subject: Re: [R] legend position
 
 It occurs to me that perhaps you're referring to the 'color bar' on the right
 of the plot.  AFAIK you cannot get at that from the raster::plot method.  
 However  lattice::levelplot does allow you to manipulate or remove that
 colorbar.
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/legend-position-tp4681489p4681497.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org 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.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] legend position

2013-12-02 Thread David Carlson
It is not straightforward unless you want the legend in the
right or the bottom margins. To put the legend inside the plot
region it is simplest to use image() to plot the raster file and
then image.plot(legend.only=TRUE) to add the legend. In addition
to reading the help page for plot{raster}, you also need the
pages for image{raster} and image.plot{fields}. Here are two
simple examples.

image(r,  col=rev(terrain.colors(255)))
plot(r, horizontal=TRUE, smallplot=c(.15, .5, .84, .86),
legend.only=TRUE)

image(r,  col=rev(terrain.colors(255)))
plot(r, smallplot=c(.15, .17, .5, .85), legend.only=TRUE)

-
David L Carlson
Department of Anthropology
Texas AM University
College Station, TX 77840-4352

-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of philippe
massicotte
Sent: Monday, December 2, 2013 1:22 PM
To: r-help@r-project.org
Subject: [R] legend position

Hi all. 
I'm ploting a raster and I can't find the proper way to move the
legend. For example,
r = raster(system.file(external/test.grd,
package=raster))plot(r)
How can I put the legend at the desired position?
Thank in advance,Phil 
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] legend position

2013-12-02 Thread philippe massicotte
Thank you David, it is exactly what I needed.
Regards,Phil

 From: dcarl...@tamu.edu
 To: pmassico...@hotmail.com; r-help@r-project.org
 Subject: RE: [R] legend position
 Date: Mon, 2 Dec 2013 14:29:06 -0600
 
 It is not straightforward unless you want the legend in the
 right or the bottom margins. To put the legend inside the plot
 region it is simplest to use image() to plot the raster file and
 then image.plot(legend.only=TRUE) to add the legend. In addition
 to reading the help page for plot{raster}, you also need the
 pages for image{raster} and image.plot{fields}. Here are two
 simple examples.
 
 image(r,  col=rev(terrain.colors(255)))
 plot(r, horizontal=TRUE, smallplot=c(.15, .5, .84, .86),
 legend.only=TRUE)
 
 image(r,  col=rev(terrain.colors(255)))
 plot(r, smallplot=c(.15, .17, .5, .85), legend.only=TRUE)
 
 -
 David L Carlson
 Department of Anthropology
 Texas AM University
 College Station, TX 77840-4352
 
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of philippe
 massicotte
 Sent: Monday, December 2, 2013 1:22 PM
 To: r-help@r-project.org
 Subject: [R] legend position
 
 Hi all. 
 I'm ploting a raster and I can't find the proper way to move the
 legend. For example,
 r = raster(system.file(external/test.grd,
 package=raster))plot(r)
 How can I put the legend at the desired position?
 Thank in advance,Phil   
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org 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.
 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Legend position

2013-09-02 Thread Moshiur Rahman
Dear R-helpers,

I'm trying to combine two box plots having two dependent variables:

var1- Orange.area and

var2- Iridescent.area;

two independent categorical factors (each has two levels - 'High'  'Low'):

fact1- Quantity

fact2- Quality


the data frame (df) is:

   Quantity Quality Orange.area Iridescent.area
1  HighHigh   8.240  12.550
2  High Low  12.690  10.470
3  HighHigh  10.340   4.350
4  High Low  11.430   8.890
5  HighHigh   6.203   6.809
6   Low Low   1.750   7.040
7   LowHigh   6.060   4.930
8   Low Low   5.630   5.980
9   LowHigh   6.540   5.360
10  Low Low   8.458   4.710



I tried to plot them with the following codes:

library(ggplot2)
library(gridExtra)
## 1st plot
p1 - qplot(as.factor(Quantity), Orange.area, data=df, geom = boxplot,
fill= Quality)
p1 -p1 + geom_boxplot() +scale_fill_manual(values = c(dark grey,
white), legend=FALSE)
p1 - p1 + labs(x=Quantity, y=Orange area)
p1 - p1 + stat_summary(fun.y = mean, geom = point, color = black,
aes(group=Quality))
p1 - p1 + stat_summary(fun.y = mean, geom = line, aes(group = Quality))
p1 - p1  +theme_bw()+
  theme(axis.line = element_line(colour = black),
strip.text.x = element_blank(),# remove top level title (high and
low)
strip.background = element_blank(),# remove top level background
panel.grid.major = element_blank(),# remove grid line within the
plot
panel.grid.minor = element_blank(),
panel.border = element_blank())
## 2nd plot
p2 - qplot(as.factor(Quantity), Iridescent.area, data=df, geom =
boxplot, fill= Quality)
p2 -p2 + geom_boxplot() +scale_fill_manual(values = c(dark grey,
white))
p2 - p2 + labs(x=Quantity, y=Iridescent area)
p2 - p2 + stat_summary(fun.y = mean, geom = point, color = black,
aes(group=Quality))
p2 - p2 + stat_summary(fun.y = mean, geom = line, aes(group = Quality))
p2 - p2  +
  theme_bw()+
  theme(axis.line = element_line(colour = black),
strip.text.x = element_blank(),# remove top level title (high and
low)
strip.background = element_blank(),# remove top level background
panel.grid.major = element_blank(),# remove grid line within the
plot
panel.grid.minor = element_blank(),
panel.border = element_blank())
## combining two plots as one plot
sidebysideplot - grid.arrange(p1, p2, ncol=2)

and got the plot which sueezed the 2nd plot having legend on its middle of
the right side.

But I want to have the legend on the top right corner with any change of
the 2nd plot (both plots should be the same size).

Is there any help? Any effort will be appreciated...

Cheers,

Moshi
-- 
MD. MOSHIUR RAHMAN
PhD Candidate
School of Animal Biology/Zoology (M092)
University of Western Australia
35 Stirling Hwy, Crawley, WA, 6009
Australia.
Mob.: 061-425205507

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] legend position help

2012-08-16 Thread Greg Snow
A quick hack to give you space between the line and point (if you only
used solid lines) is to specify lty='ff' to the legend function.

If you want more control then look at setting trace=TRUE and
plot=FALSE and looking at the printed outcome and the return value
from legend.  This does not plot the legend, but gives you the
information that you can use to create the legend yourself (and could
therefore move the pieces that you want moved).

On Wed, Aug 15, 2012 at 8:05 PM, Jinsong Zhao jsz...@yeah.net wrote:
 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 jsz...@yeah.net 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

 __
 R-help@r-project.org 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.
538...@gmail.com

__
R-help@r-project.org 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.


[R] legend position help

2012-08-15 Thread Jinsong Zhao

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

__
R-help@r-project.org 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.


Re: [R] legend position help

2012-08-15 Thread Greg Snow
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 jsz...@yeah.net 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

 __
 R-help@r-project.org 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.
538...@gmail.com

__
R-help@r-project.org 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.


Re: [R] legend position help

2012-08-15 Thread Jinsong Zhao

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 jsz...@yeah.net 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

__
R-help@r-project.org 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.






__
R-help@r-project.org 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.


Re: [R] legend position in interaction.plot

2011-08-11 Thread Peter Maclean
How do I move the legend from default position (right and within the plot) to 
the bottomleft of the plot?
 
interaction.plot(YEAR, ID GROWTH, legend=TRUE, col = 2:7,xlab=Year, 
   ylim=c(0,2), ylab=Growth,leg.bty = o)

Peter Maclean
Department of Economics
UDSM

__
R-help@r-project.org 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.


Re: [R] legend position in interaction.plot

2011-08-11 Thread David Winsemius


On Aug 11, 2011, at 3:38 AM, Peter Maclean wrote:

How do I move the legend from default position (right and within the  
plot) to the bottomleft of the plot?


interaction.plot(YEAR, ID GROWTH, legend=TRUE, col = 2:7,xlab=Year,
   ylim=c(0,2), ylab=Growth,leg.bty = o)


You display the code from interaction.plot, make a new function, and  
hack the location code for the legend x and y legend arguments which  
are created as the 'xleg' and 'yleg' arguments internally for  
positioning of the legend() and the text(...trace.label) pringint   
and then you make the call again with your new function. Out of the  
box the function adds extra xlim space on the basis of the value of  
the 'legend' argument to interaction.plot to make sure the legend does  
not get over-run by the the lines. The y positioning is determined  
entirely by the ylim. There is no provision that I see for user- 
supplied positioning arguments. It would be cleaner to add such named  
arguments after the ,... in the argument list, since attempting to  
pass named arguments directly to legend will generate a bunch of  
warnings.


--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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.


[R] legend position in barplot

2011-03-20 Thread Hongwei Dong
Hi, R users,

I there a way that I can control the position of the legend while using
barplot function?

For example:

a-matrix(c(0,0,0.5,0.8,0.9,0.9),2,3)
colnames(a)-c(X,Y,Z)
rownames(a)-c(A,B)
a
barplot(a,width = 0.2,legend =
TRUE,axes=FALSE,col=c(coral3,steelblue3),beside=TRUE)

In this case, the legend is too small, and I want to move it to the left.
Thanks.


Regards
Gary

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] legend position in barplot

2011-03-20 Thread Uwe Ligges

On 20.03.2011 18:52, Hongwei Dong wrote:

Hi, R users,

I there a way that I can control the position of the legend while using
barplot function?

For example:

a-matrix(c(0,0,0.5,0.8,0.9,0.9),2,3)
colnames(a)-c(X,Y,Z)
rownames(a)-c(A,B)
a
barplot(a,width = 0.2,legend =
TRUE,axes=FALSE,col=c(coral3,steelblue3),beside=TRUE)

In this case, the legend is too small, and I want to move it to the left.
Thanks.


Yes, e.g.:

barplot(a, width = 0.2, legend = TRUE, axes = FALSE,
col = c(coral3, steelblue3), beside = TRUE,
args.legend = list(x=topleft))

Uwe Ligges





Regards
Gary

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


__
R-help@r-project.org 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.


[R] Legend Position

2008-11-18 Thread Richardson, Patrick
List,

Is there any way to specify the position of the legend from within the 
following code? If so, how can I do it. As it stands it in the bottom left 
corner and I want to move it to the top right.  I'm not sure if I can use the 
default plot or if I need to go with the lattice package.  Suggestions much 
appreciated.

plot(y, xlab=Survival Time (Months), ylab=Survival Probability,
mark.time=TRUE, col = c(red, blue),legend.text = c(Locally Advanced, 
Metastatic),
main=Kaplan-Meier Curve of Survival Times - Stratified by Group, lwd=3)


Thanks,

_
Patrick Richardson
Biostatistician - Program of Translational Medicine
Van Andel Research Institute - Webb Lab
333 Bostwick Avenue NE
Grand Rapids, MI  49503
ph. 616.234.5787


This email message, including any attachments, is for th...{{dropped:9}}

__
R-help@r-project.org 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.


Re: [R] Legend Position

2008-11-18 Thread Jorge Ivan Velez
Dear Patrick,
Try this:

plot(y, xlab=Survival Time (Months), ylab=Survival Probability,
mark.time=TRUE, col = c(red, blue),
main=Kaplan-Meier Curve of Survival Times - Stratified by Group, lwd=3)
legend('topright',c(Locally Advanced,
Metastatic),lty=1,col.text=c('red','blue'))

See ?legend for more information.

HTH,

Jorge




On Tue, Nov 18, 2008 at 1:05 PM, Richardson, Patrick 
[EMAIL PROTECTED] wrote:

 List,

 Is there any way to specify the position of the legend from within the
 following code? If so, how can I do it. As it stands it in the bottom left
 corner and I want to move it to the top right.  I'm not sure if I can use
 the default plot or if I need to go with the lattice package.  Suggestions
 much appreciated.

 plot(y, xlab=Survival Time (Months), ylab=Survival Probability,
 mark.time=TRUE, col = c(red, blue),legend.text = c(Locally Advanced,
 Metastatic),
 main=Kaplan-Meier Curve of Survival Times - Stratified by Group, lwd=3)


 Thanks,

 _
 Patrick Richardson
 Biostatistician - Program of Translational Medicine
 Van Andel Research Institute - Webb Lab
 333 Bostwick Avenue NE
 Grand Rapids, MI  49503
 ph. 616.234.5787


 This email message, including any attachments, is for ...{{dropped:13}}

__
R-help@r-project.org 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.


Re: [R] Legend position outside

2008-04-12 Thread Greg Snow
Type ?par at the command line to bring up the help page, then scroll down and 
read the sections on xpd and usr.



From: Edwin Sendjaja [mailto:[EMAIL PROTECTED]
Sent: Fri 4/11/2008 9:56 PM
To: Greg Snow; r-help@r-project.org
Subject: Re: [R] Legend position outside



Hello Gred,

I try to read R-Reference, but I cant understand it.

What does par (xpd=NA)? and par('usr')) mean? Thank you.






Kind regards,

Edwin



Am Freitag, 11. April 2008 19:19:24 schrieben Sie:
 Yes, here is one way:
  plot(1:10, pch=1:2)
  par(xpd=NA)
  tmp.u - par('usr')
  legend(tmp.u[1], tmp.u[4], xjust=0, yjust=0, c('a','b'), pch=1:2)

 You will probably want to increase the margins for a real case.  See
 ?par and the 'xpd' entry for details on the clipping and ?legend for
 more details on creating the legend.

 Hope this helps,





[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Legend position outside

2008-04-11 Thread Edwin Sendjaja
Hello,

Is it possible to get the legend box outside the graphic?


Kind regards,

Edwin

__
R-help@r-project.org 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.


[R] Legend position outside

2008-04-11 Thread Edwin Sendjaja
Hello,

Is it possible to get the legend box outside the graphic?


Kind regards,

Edwin

__
R-help@r-project.org 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.


Re: [R] Legend position outside

2008-04-11 Thread Greg Snow
Yes, here is one way:

 plot(1:10, pch=1:2)
 par(xpd=NA)
 tmp.u - par('usr')
 legend(tmp.u[1], tmp.u[4], xjust=0, yjust=0, c('a','b'), pch=1:2)
 

You will probably want to increase the margins for a real case.  See
?par and the 'xpd' entry for details on the clipping and ?legend for
more details on creating the legend.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Edwin Sendjaja
 Sent: Friday, April 11, 2008 1:01 PM
 To: r-help@r-project.org
 Subject: [R] Legend position outside
 
 Hello,
 
 Is it possible to get the legend box outside the graphic?
 
 
 Kind regards,
 
 Edwin
 
 __
 R-help@r-project.org 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.
 

__
R-help@r-project.org 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.


Re: [R] Legend position outside

2008-04-11 Thread Edwin Sendjaja
Hello Gred,

I try to read R-Reference, but I cant understand it.

What does par (xpd=NA)? and par('usr')) mean? Thank you.






Kind regards,

Edwin 



Am Freitag, 11. April 2008 19:19:24 schrieben Sie:
 Yes, here is one way:
  plot(1:10, pch=1:2)
  par(xpd=NA)
  tmp.u - par('usr')
  legend(tmp.u[1], tmp.u[4], xjust=0, yjust=0, c('a','b'), pch=1:2)

 You will probably want to increase the margins for a real case.  See
 ?par and the 'xpd' entry for details on the clipping and ?legend for
 more details on creating the legend.

 Hope this helps,

__
R-help@r-project.org 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.