[R] legend

2005-06-22 Thread Thomas Steiner
I color some area grey with polygon() (with a red border) and then I
want to have the dashed red border in the legend as well. How do I
manage it?

And I want to mix (latex) expressions with text in my legend.

Just execute my lines below and you know want I mean. Or pass by at
http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online.

Thomas


bm <- function(n=500, from=0, to=1) {
  x=seq(from=from,to=to,length=n)
  BM<-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n
  cbind(x,BM)
}
gbm <- function(bm,S0=1,sigma=0.1,mu=1) {
  gbm=S0
  for (t in 2:length(bm[,1])) {
gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2])
  }
  cbind(bm[,1],gbm)
}

set.seed(9826064)
cs=c("dark green", "steelblue", "red", "yellow")

#png(filename = "GBM.png", width=1600, height=1200, pointsize = 12)
par(bg="lightgrey")
x=seq(from=0,to=1,length=500)
plot(x=x, y=exp(0.7*x), type="n", xlab="Zeit", ylab="", ylim=c(1,3.5))
polygon(x=c(x,rev(x)),
y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col="grey",
border=cs[3], lty="dashed")
lines(x=x,y=exp(0.7*x), type="l", lwd=3, col=cs[1])
lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2])
lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3])
lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4])
title(main="Geometrische Brownsche Bewegung",cex.main=2.5)
legend(x=0,y=3.5,legend=c("exp(0.7x)","mu=0.7, sigma=0.4","mu=0.7,
sigma=0.2","mu=0.7, sigma=0.1","Standardabweichung für 
sigma=0.2"),lwd=c(4,4,4,4,12),col=c(cs,"grey"),bg="transparent",cex=1.15)
#dev.off()

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend

2005-11-13 Thread Mark Miller
I use the following to plot two graphs over each other and then insert a 
legend, but the two items in the legend both come up the same colour

x = seq(0,30,0.01)
plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs 
for Data and\n Fitted PDF over Entire 15 Weeks')
lines(x, pexp(x,0.415694806),col="red")
legend(x=5,y=0.2 , legend=c("Data Set","Fitted PDF"),col=c("black","red"))

Many thanks
Mark Miller

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend()

2007-07-31 Thread amna khan
Hi Sir
How can I use legend() outside th e plot.
Please guid in this regard.
Thanks

-- 
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email:
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch 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

2004-06-23 Thread Perez Martin, Agustin
DeaR UseRs:

I want to put a legend in my plot. In the first line of the legend I want to
put a box filled but in the second one I would like to put a lty=2

Of course it must appear with different colors.

Thanks.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend

2004-11-19 Thread Losier, Randy J

I have recently converted from S-Plus (Dec Alpha) to R (Mandrake 10.0). The
differences are subtle but in some cases not easily converted. My Splus
Command plotting deck was over 1200 lines and R has simplified this down to
900 lines so far. I do a lot of mapping with polygons and I am trying to
figure out how to increase the default size of the fill boxes in the legend
call. Splus had a convienient rectangle call in the Key module that did
this. Will I have to use the lattice library for this functionality? Also,
how does one get around removing the grey background produce by the
following xyplot. The postscript works great but my boss wants the figures
for the Microsoft world.
Thanks 
Randy

Coding used for fill question?
dense <- rep(0,length(LTtempmean))
for(i in 1:length(LTtempmean)){
if(LTtempmean[i] < 2)dense[i]=5
else if(LTtempmean[i] >= 2 & LTtempmean[i] < 4)dense[i]=12
else if(LTtempmean[i] >= 4 & LTtempmean[i] < 6)dense[i]=30
else if(LTtempmean[i] >= 6 & LTtempmean[i] < 8)dense[i]=45
else if(LTtempmean[i] >= 8 & LTtempmean[i] < 10)dense[i]=62
else if(LTtempmean[i] >= 10)dense[i]=99}
dense <- paste("grey",dense,sep="")
axislong <- c(-68,-57)
axislat <- c(42,48)
par(fig=c(0,1.0,.43,1.0))
plot(axislong,axislat,type='n',xlim=c(-68,-57),err=-1,mgp=c(0,.5,0),
ylim=c(41.5,47.5),xlab="",ylab="",xaxt="n",cex=.8)
#plot Scotian Shelf Map
polygon(long,lat,density=-1,angle=45,border=F,col="grey",err=-1)
par(new=T,xaxt="n",yaxt="n")
#plot coastline outline
lines(longcoast,latcoast)
#Shade in Polygons   
polygon(strlong,strlat,border=T,density=-1,col=dense)  
polygon(strlong74,strlat74,border=T,density=-1,col=dense[30])
#Draw outlines of Strata
polygon(strlong,strlat,border=T,density=0)
par(cex=.8)
legend(-61.7,42.6,
c("Below 2.0","2.0 to 4.0","4.0 to 6.0","6.0 to 8.0","8.0 to 10.0","10 &
Above"),
 
fill=c('grey5','grey12','grey30','grey45','grey62','grey99'),ncol=2,bty="o",
bg='white')
text(-61.7,42.6,"Temperature Anomaly",adj=c(0,0))

##Coding used for grey background issue.
require(grid)
library(lattice)
background<-trellis.par.get("background")
background$col<-"transparent"
trellis.par.set("background",background)
caption<-"Figure 4: Time series of sampling depths for 4VW summer surveys.
Numbers\nin strip panels indicate strata locations. Closed circles represent
one sampled\nstation."
#function
format.figure<-function(latticePlot,caption){
vp1<-viewport(x=0,y=.08,width=1,height=.8,just=c("left","bottom"))
vp2<-viewport(x=0,y=0,width=1,height=.06,just=c("left","bottom"))
pushViewport(vp1)
print(latticePlot,newpage=F)
#grid.rect()
popViewport(1)
pushViewport(vp2)
grid.text(caption,x=.1,just=c("left","bottom"),gp=gpar(cex=.99))
#grid.rect()
popViewport(1)
}
#postscript("fig20.eps",horizontal=F,width=7.0,height=9.3)
png("fig20.png", bg = "transparent", width = 480, height = 640,pointsize =
12,  res = 1200)
caption <- "Figure 20: Time series of near-bottom salinities for 4X summer
surveys.\nNumbers in strip panels indicate strata locations. Closed circles
represent one\nsampled station."
randy <- xyplot(xsal~xyr | xstrat,type="p",ylab="Salinity
(psu)",xlab="Year",background="white",
pch=16,mkh=.03,
as.table=T,
strip = function(...) strip.default(..., style = 1))
format.figure(randy,caption)
dev.off()

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend

2003-02-12 Thread Wilkinson, Mark

I think I'm missing something tonight in the usage of 'legend':

plot(0, type="n")
legend(locator(1), month.abb[1:5], pch=15, col=1:5)

gives me something similar to what I want. But

legend(locator(1), month.abb[1:5], fill=T, col=1:5)

gives me 5 black boxes.

What am I doing wrong?

Thank you, 


> version
 _
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major1
minor6.1
year 2002
month11
day  01
language R


Mark Wilkinson
Informatics Analyst
St. Jude Children's Research Hospital
Department of Pharmaceutical Sciences

The opinions expressed here are my own and do not necessarily represent
those of St. Jude Children's Research Hospital.

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



Re: [R] legend

2005-06-22 Thread Uwe Ligges
Thomas Steiner wrote:

> I color some area grey with polygon() (with a red border) and then I
> want to have the dashed red border in the legend as well. How do I
> manage it?
> 
> And I want to mix (latex) expressions with text in my legend.


Both points are not that easy to solve, hence I'd like to suggest to 
write your own little function that generates the legend.

Starting at the upper left, calculating the stringheight, painting the 
(party very special) symbols, and adding the text line by line seems to 
be the most easiest solution here (which is not that nice, though.

Uwe Ligges


> Just execute my lines below and you know want I mean. Or pass by at
> http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online.
> 
> Thomas
> 
> 
> bm <- function(n=500, from=0, to=1) {
>   x=seq(from=from,to=to,length=n)
>   BM<-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n
>   cbind(x,BM)
> }
> gbm <- function(bm,S0=1,sigma=0.1,mu=1) {
>   gbm=S0
>   for (t in 2:length(bm[,1])) {
> gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2])
>   }
>   cbind(bm[,1],gbm)
> }
> 
> set.seed(9826064)
> cs=c("dark green", "steelblue", "red", "yellow")
> 
> #png(filename = "GBM.png", width=1600, height=1200, pointsize = 12)
> par(bg="lightgrey")
> x=seq(from=0,to=1,length=500)
> plot(x=x, y=exp(0.7*x), type="n", xlab="Zeit", ylab="", ylim=c(1,3.5))
> polygon(x=c(x,rev(x)),
> y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col="grey",
> border=cs[3], lty="dashed")
> lines(x=x,y=exp(0.7*x), type="l", lwd=3, col=cs[1])
> lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2])
> lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3])
> lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4])
> title(main="Geometrische Brownsche Bewegung",cex.main=2.5)
> legend(x=0,y=3.5,legend=c("exp(0.7x)","mu=0.7, sigma=0.4","mu=0.7,
> sigma=0.2","mu=0.7, sigma=0.1","Standardabweichung für 
> sigma=0.2"),lwd=c(4,4,4,4,12),col=c(cs,"grey"),bg="transparent",cex=1.15)
> #dev.off()
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] legend

2005-06-22 Thread Paul Murrell
Hi


Uwe Ligges wrote:
> Thomas Steiner wrote:
> 
> 
>>I color some area grey with polygon() (with a red border) and then I
>>want to have the dashed red border in the legend as well. How do I
>>manage it?
>>
>>And I want to mix (latex) expressions with text in my legend.
> 
> 
> 
> Both points are not that easy to solve, hence I'd like to suggest to 
> write your own little function that generates the legend.
> 
> Starting at the upper left, calculating the stringheight, painting the 
> (party very special) symbols, and adding the text line by line seems to 
> be the most easiest solution here (which is not that nice, though.


I don't think it's too bad.  For example, try replacing the original ...

legend(x=0,y=3.5,legend=c("exp(0.7x)","mu=0.7, sigma=0.4","mu=0.7,
sigma=0.2","mu=0.7, sigma=0.1","Standardabweichung für 
sigma=0.2"),lwd=c(4,4,4,4,12),col=c(cs,"grey"),bg="transparent",cex=1.15)

... with ...

# Use grid and gridBase so you've got some sensible
# coordinate systems to work within
library(grid)
library(gridBase)
# Align a grid viewport with the plotting region
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
# Define labels and colours
# Labels are mathematical expressions
labels <- expression("exp(0.7x)",
 list(mu == 0.7,sigma == 0.4),
 list(mu == 0.7,sigma == 0.2),
 list(mu == 0.7, sigma == 0.1),
 paste("Standardabweichung für ",sigma == 0.2))
cols <- cs
# Draw each legend item on its own line
# Top line 1cm in from top-left corner
for (i in 1:5) {
   x <- unit(1, "cm")
   y <- unit(1, "npc") - unit(1, "cm") - unit(i, "lines")
   if (i < 5) {
 grid.lines(unit.c(x, unit(2, "cm")), y + unit(0.5, "lines"),
gp=gpar(col=cols[i], lwd=3))
   } else {
 grid.rect(x, y, width=unit(1, "cm"),
   height=unit(1, "lines"),
   gp=gpar(fill="grey", col=cs[3], lty="dashed"),
   just=c("left", "bottom"))
   }
   grid.text(labels[i], x + unit(1.5, "cm"), y,
 just=c("left", "bottom"))
}
# clean up
popViewport(3)

... that's a bit of typing, but if you need to do more than one, it 
would go inside a function with labels and cols as arguments (and '5' 
replaced by 'length(labels)') without too much trouble.

(In this case, you could also pretty easily just do the main plot using 
grid and avoid having to use gridBase.)

Paul


>>Just execute my lines below and you know want I mean. Or pass by at
>>http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online.
>>
>>Thomas
>>
>>
>>bm <- function(n=500, from=0, to=1) {
>>  x=seq(from=from,to=to,length=n)
>>  BM<-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n
>>  cbind(x,BM)
>>}
>>gbm <- function(bm,S0=1,sigma=0.1,mu=1) {
>>  gbm=S0
>>  for (t in 2:length(bm[,1])) {
>>gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2])
>>  }
>>  cbind(bm[,1],gbm)
>>}
>>
>>set.seed(9826064)
>>cs=c("dark green", "steelblue", "red", "yellow")
>>
>>#png(filename = "GBM.png", width=1600, height=1200, pointsize = 12)
>>par(bg="lightgrey")
>>x=seq(from=0,to=1,length=500)
>>plot(x=x, y=exp(0.7*x), type="n", xlab="Zeit", ylab="", ylim=c(1,3.5))
>>polygon(x=c(x,rev(x)),
>>y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col="grey",
>>border=cs[3], lty="dashed")
>>lines(x=x,y=exp(0.7*x), type="l", lwd=3, col=cs[1])
>>lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2])
>>lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3])
>>lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4])
>>title(main="Geometrische Brownsche Bewegung",cex.main=2.5)
>>legend(x=0,y=3.5,legend=c("exp(0.7x)","mu=0.7, sigma=0.4","mu=0.7,
>>sigma=0.2","mu=0.7, sigma=0.1","Standardabweichung für 
>>sigma=0.2"),lwd=c(4,4,4,4,12),col=c(cs,"grey"),bg="transparent",cex=1.15)
>>#dev.off()
>>
>>__
>>R-help@stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend

2005-11-13 Thread Sundar Dorai-Raj


Mark Miller wrote:
> I use the following to plot two graphs over each other and then insert a 
> legend, but the two items in the legend both come up the same colour
> 
> x = seq(0,30,0.01)
> plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs 
> for Data and\n Fitted PDF over Entire 15 Weeks')
> lines(x, pexp(x,0.415694806),col="red")
> legend(x=5,y=0.2 , legend=c("Data Set","Fitted PDF"),col=c("black","red"))
> 
> Many thanks
> Mark Miller
> 

Hi, Mark,

You want to use "text.col" in legend instead of "col":

set.seed(1)
z <- rexp(30, 0.415694806)
x <- seq(0, 30, 0.1)
plot(ecdf(z), do.point = FALSE)
lines(x, pexp(x, 0.415694806), col="red")
legend(x = 5, y = 0.2, legend = c("Data Set", "Fitted PDF"),
text.col = c("black", "red"))

--sundar

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend

2005-11-13 Thread Adaikalavan Ramasamy
And you want to have different colored lines but black texts, try

 legend(x = 5, y = 0.2, legend = c("Data Set", "Fitted PDF"),
col = c("black", "red"), lty=1)

The advantage of this is that you can use dotted (lty option) or lines
with different weights (lwd option).

Regards, Adai



On Sun, 2005-11-13 at 06:46 -0600, Sundar Dorai-Raj wrote:
> 
> Mark Miller wrote:
> > I use the following to plot two graphs over each other and then insert a 
> > legend, but the two items in the legend both come up the same colour
> > 
> > x = seq(0,30,0.01)
> > plot(ecdf(complete), do.point=FALSE, main = 'Cummlative Plot of Monday IATs 
> > for Data and\n Fitted PDF over Entire 15 Weeks')
> > lines(x, pexp(x,0.415694806),col="red")
> > legend(x=5,y=0.2 , legend=c("Data Set","Fitted PDF"),col=c("black","red"))
> > 
> > Many thanks
> > Mark Miller
> > 
> 
> Hi, Mark,
> 
> You want to use "text.col" in legend instead of "col":
> 
> set.seed(1)
> z <- rexp(30, 0.415694806)
> x <- seq(0, 30, 0.1)
> plot(ecdf(z), do.point = FALSE)
> lines(x, pexp(x, 0.415694806), col="red")
> legend(x = 5, y = 0.2, legend = c("Data Set", "Fitted PDF"),
> text.col = c("black", "red"))
> 
> --sundar
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend + expression

2007-06-08 Thread Pedro Mardones
Dear all;

A simple? question.

I'm having a problem with a math expression in the legend of a plot
and I haven't found the way to get this to work, so any help will be
appreciate. Basically I want to include in the plot is the R-squared
and its numerical value, so I tried this:

R2c<-0.82879 # R-squared of calibration model
plot(1:10,1:10)
legend("topleft", legend=c(expression(R[c]^2==format(R2c,nsmall=2

Thanks for any hint

PM

__
R-help@stat.math.ethz.ch 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()

2007-07-31 Thread Marc Schwartz
On Tue, 2007-07-31 at 10:21 -0700, amna khan wrote:
> Hi Sir
> How can I use legend() outside th e plot.
> Please guid in this regard.
> Thanks


Create a plot, specifying outer margins to make space for the legend.
Then move the legend to the open region.

# Set 'xpd' to NA so that the legend is not clipped
# at the plot region, which it is by default
par(xpd = NA)

# Make some room at the right hand side
par(oma = c(0, 0, 0, 10))

# Do the plot
plot(1:5)

# Do the legend and use 'inset' to move the legend to
# the right hand outer margin
legend("topright", legend = 1:5, inset = c(-.4, .0))



You can adjust the outer margin settings and the 'inset' value as you
may require to make room for the legend on the side required.

See ?par and ?legend for more information.

Another option would be to use layout() to create more than one plot
region, perhaps adjusting the heights and/or widths of the plot regions,
such that the data plot goes into one region and the legend into the
other.  See ?layout for more information.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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 function

2007-02-13 Thread amna khan
Dear Sir

Lengend add a bix containing plot discription in the existing plot. Is there
any function which decribe the lines in a plot outside the existing plot?

I have also a question related to following statement. In this statement " *
" is used for plot discription. If we have plotted type="o" of plot then
what pch is to be used.

>legend(30,3.5, c("Fuel","Smoothed Fuel"), pch="* ", lty=c(0,1))

Please Help in this regard

AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email:
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 font

2007-02-14 Thread Tyler Smith
Hi,

I'd like to make the text in my legends italic, but I can't figure out
how to do so. font=3 doesn't work. Googling brings up the possibility
of expression(italic()), which produces italics, but I can't get this
to work with my label data, which is a vector of strings:

  legend(locator(1), legend = levels(factor(label.vector)),
 col = plotting.colours, pch =plotsym.bw, cex = 0.7 )

How can I do this?

-- 
Regards,

Tyler Smith

__
R-help@stat.math.ethz.ch 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 question

2007-02-28 Thread Emili Tortosa-Ausina
Hi to all,

I'm sorry for posting this question, I am sure I am missing something 
important but after reading the documentation I cannot find where the 
problem is.

I want to add a legend to a figure. If I use a simple example drawn 
from the R Reference Manual such as, for instance:

x <- seq(-pi, pi, len = 65)
plot(x, sin(x), type="l", col = 2)
legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)

then everything works just fine.

However, if I use other data such as, for instance:

y<-c(1960, 1965, 1970, 1975)
z<-c(1, 2, 3, 4)
plot(y, z, type="l", col = 2)
legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)

then the legend is not shown.

Any hints?

Thanks in advance,

Emili

__
R-help@stat.math.ethz.ch 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

2004-06-23 Thread Ko-Kang Kevin Wang
Hi,

- Original Message - 
From: "Perez Martin, Agustin" <[EMAIL PROTECTED]>
To: "lista R help (E-mail)" <[EMAIL PROTECTED]>
Sent: Wednesday, June 23, 2004 9:19 PM
Subject: [R] legend


> DeaR UseRs:
>
> I want to put a legend in my plot. In the first line of the legend I want
to
> put a box filled but in the second one I would like to put a lty=2

Have you looked at ?lengend

It's got some good examples.

Kevin

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] legend

2004-06-23 Thread Jim Lemon
Perez Martin, Agustin wrote:
> DeaR UseRs:
>
> I want to put a legend in my plot. In the first line of the legend I want
> to put a box filled but in the second one I would like to put a lty=2
>
> Of course it must appear with different colors.
>
I think I wrote this function about a year ago for someone, but I couldn't 
find it anywhere. Here it is again.

Jim
add.legend.bars<-function(legend.info,whichbars,col,border="black") {
 nelements<-length(legend.info$text$y)
 left<-rep(legend.info$rect$left+
  0.1*(legend.info$text$x[1]-legend.info$rect$left),nelements)
 right<-rep(legend.info$rect$left+
  0.8*(legend.info$text$x[1]-legend.info$rect$left),nelements)
 top<-legend.info$text$y+(legend.info$text$y[1]-legend.info$text$y[2])/3
 bottom<-top-(legend.info$text$y[1]-legend.info$text$y[2])/1.5
 rect(left[whichbars],bottom[whichbars],
  right[whichbars],top[whichbars],
  col=col,border=border)
}
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] legend

2003-02-12 Thread Hedderik van Rijn
legend(locator(1), month.abb[1:5], fill=T, col=1:5)

gives me 5 black boxes.


Try:

legend(locator(1), month.abb[1:5], fill=1:5)


What am I doing wrong?


The "T" is interpreted as (equal to?) a "1", so you're requesting the 
boxes to be filled with color 1, which is black.

 - Hedderik.

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] legend

2003-02-12 Thread Aleksey Y Naumov
Try:

legend(locator(1), month.abb[1:5], fill=1:5)

'col' takes care of the color of points and lines.

Aleksey

On Wed, 12 Feb 2003, Wilkinson, Mark wrote:

> 
> I think I'm missing something tonight in the usage of 'legend':
> 
> plot(0, type="n")
> legend(locator(1), month.abb[1:5], pch=15, col=1:5)
> 
> gives me something similar to what I want. But
> 
> legend(locator(1), month.abb[1:5], fill=T, col=1:5)
> 
> gives me 5 black boxes.
> 
> What am I doing wrong?
> 
> Thank you, 
> 
> 
> > version
>  _
> platform i686-pc-linux-gnu
> arch i686
> os   linux-gnu
> system   i686, linux-gnu
> status
> major1
> minor6.1
> year 2002
> month11
> day  01
> language R
> 
> 
> Mark Wilkinson
> Informatics Analyst
> St. Jude Children's Research Hospital
> Department of Pharmaceutical Sciences
> 
> The opinions expressed here are my own and do not necessarily represent
> those of St. Jude Children's Research Hospital.
> 
> __
> [EMAIL PROTECTED] mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
>

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



[R] legend positioning problems

2006-11-13 Thread Schweitzer, Markus
Hello,

I have several Barplots I want to plot. I also want to include a legend.
Since my Barplots are very different I ve dicided to put the legend in
the top left corner.

Unfortunately, sometimes there is a part of a bar just below the legend.

This makes it difficult to see the legend itself or the barplot.

All I found out so far, is to make the backgroundcolor of the legend
white or so, but I would couldn t see the bar anymore.

Is there a way, to position the legend "excel-like" on the outside the
plot on the side? or
Is there a possibility to use sort of an alpha-factor to make the
background white but slightly invisible so that there is a contrast?

I hope you can help me out and thank you in advance!

#Example:
barplot(VADeaths)
legend("topleft", c("1x", "2x", "3x", "4x", "5x"),
bg="white"))




Markus Schweitzer - http://www.pokertips.tk

__
R-help@stat.math.ethz.ch 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 + expression

2007-06-08 Thread Peter Ruckdeschel
what about

legend("topleft",
legend = bquote( R[c]2 == .(format(R2c,nsmall=2)) )
   )

HTH,
 Peter

__
R-help@stat.math.ethz.ch 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 + expression

2007-06-08 Thread Marc Schwartz
On Fri, 2007-06-08 at 17:27 -0400, Pedro Mardones wrote:
> Dear all;
> 
> A simple? question.
> 
> I'm having a problem with a math expression in the legend of a plot
> and I haven't found the way to get this to work, so any help will be
> appreciate. Basically I want to include in the plot is the R-squared
> and its numerical value, so I tried this:
> 
> R2c<-0.82879 # R-squared of calibration model
> plot(1:10,1:10)
> legend("topleft", legend=c(expression(R[c]^2==format(R2c,nsmall=2
> 
> Thanks for any hint
> 
> PM

Try this:

  R2c <- 0.82879

  plot(1:10,1:10)

  R2c.2 <- sprintf("%.2f", R2c)

  legend("topleft", legend = bquote(R[c]^2 == .(R2c.2)))


See ?bquote and if you search the list archives, there are more complex
examples of using 'plotmath' in legends.

Note also that 'nsmall' in format() does not fix the number of digits
after the decimal:

> format(0.82879, nsmall = 2)
[1] "0.82879"

See ?formatC and ?sprintf for better options.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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 on graph

2007-08-12 Thread akki
Hi,
I have a problem when I want to put a legend on the graph.
I do:

legend("topright", names(o), cex=0.9, col=plot_colors,lty=1:5, bty="n")

but the legend is writen into the graph (graphs' top but into the graph),
because I have values on this position. How can I write the legend on top
the graph without the legend writes on graph's values.

Thanks.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 on graph

2007-08-13 Thread Nguyen Dinh Nguyen
Hi Akki, 
Then you may need to increase y-axis scale by ylim=c(min,max)
Cheers
Nguyen

On 8/12/07, akki <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a problem when I want to put a legend on the graph.
> I do:
>
> legend("topright", names(o), cex=0.9, col=plot_colors,lty=1:5, bty="n")
>
> but the legend is writen into the graph (graphs' top but into the graph),
> because I have values on this position. How can I write the legend on top
> the graph without the legend writes on graph's values.
>
> Thanks.
__
R-help@stat.math.ethz.ch 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 font

2007-02-14 Thread Duncan Murdoch
On 2/14/2007 1:32 PM, Tyler Smith wrote:
> Hi,
> 
> I'd like to make the text in my legends italic, but I can't figure out
> how to do so. font=3 doesn't work. Googling brings up the possibility
> of expression(italic()), which produces italics, but I can't get this
> to work with my label data, which is a vector of strings:
> 
>   legend(locator(1), legend = levels(factor(label.vector)),
>  col = plotting.colours, pch =plotsym.bw, cex = 0.7 )
> 
> How can I do this?

This should work:

plot(1,1)
savefont <- par(font=3)
legend("topright", legend=c('Label 1', 'Label 2'), pch=1:2)
par(savefont)

Duncan Murdoch

__
R-help@stat.math.ethz.ch 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 font

2007-02-14 Thread Tyler Smith
On Wed, Feb 14, 2007 at 02:40:47PM -0500, Duncan Murdoch wrote:
> On 2/14/2007 1:32 PM, Tyler Smith wrote:
> >Hi,
> >
> >I'd like to make the text in my legends italic, 

...

> >How can I do this?
> 
> This should work:
> 
> plot(1,1)
> savefont <- par(font=3)
> legend("topright", legend=c('Label 1', 'Label 2'), pch=1:2)
> par(savefont)
> 

Thanks! I don't understand it yet, but it does indeed work.


-- 
Regards,

Tyler Smith

__
R-help@stat.math.ethz.ch 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 font

2007-02-14 Thread Duncan Murdoch
On 2/14/2007 3:12 PM, Tyler Smith wrote:
> On Wed, Feb 14, 2007 at 02:40:47PM -0500, Duncan Murdoch wrote:
>> On 2/14/2007 1:32 PM, Tyler Smith wrote:
>> >Hi,
>> >
>> >I'd like to make the text in my legends italic, 
> 
> ...
> 
>> >How can I do this?
>> 
>> This should work:
>> 
>> plot(1,1)
>> savefont <- par(font=3)
>> legend("topright", legend=c('Label 1', 'Label 2'), pch=1:2)
>> par(savefont)
>> 
> 
> Thanks! I don't understand it yet, but it does indeed work.

The idea is that the first par() command changes the default font for 
everything. (The legend() function doesn't pass any font request down to 
the graphics system, it just uses the default font.)  It also returns 
the old font setting and I saved it in "savefont".

The second par() call restores the old font setting.

Duncan Murdoch

__
R-help@stat.math.ethz.ch 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 question

2007-02-28 Thread Ranjan Maitra
On Wed, 28 Feb 2007 17:06:18 +0100 Emili Tortosa-Ausina <[EMAIL PROTECTED]> 
wrote:

> y<-c(1960, 1965, 1970, 1975)
> z<-c(1, 2, 3, 4)
> plot(y, z, type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)

your x and y are outside the plotting area. try using a different set, or 
better still use locator() to specify x, y interactively.

hth,
ranjan

__
R-help@stat.math.ethz.ch 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 question

2007-02-28 Thread Stephen Tucker
Hi Emili,

Even though you are calling your horizontal coordinate y, and vertical
coordinate z, the first and second arguments to legend(), namely x and y,
should be the horizontal and vertical coordinates, respectively; and they are
given in user coordinates (e.g., legend()'s x should be between 1960 and 1975
and legend()'s y should be between 1 and 4).

If you want to use normalized coordinates (i.e. 0 to 1), you can scale as in
this example:

legend(x = par("usr")[1] + diff(par("usr")[1:2])*normalizedCoordX,
   y = par("usr")[3] + diff(par("usr")[3:4])*normalizedCoordY,
   ...)

where normalizedCoordX and Y go from 0 to 1 (see ?par, par("usr") returns
vector of c(xmin,xmax,ymin,ymax) of user coordinates on a plot)

You can alternatively use legend(x = "topleft",...) or "bottomright", and so
on to place your legend.

If you want to add your legend outside of the plot, you should consider
increasing the margins using the 'mar' argument in par(), and also setting
par(xpd=TRUE) (so stuff can show up outside of the plotting region).

Best regards,
ST


> y<-c(1960, 1965, 1970, 1975)
> z<-c(1, 2, 3, 4)
within the data limits of your x and y)





--- Emili Tortosa-Ausina <[EMAIL PROTECTED]> wrote:

> Hi to all,
> 
> I'm sorry for posting this question, I am sure I am missing something 
> important but after reading the documentation I cannot find where the 
> problem is.
> 
> I want to add a legend to a figure. If I use a simple example drawn 
> from the R Reference Manual such as, for instance:
> 
> x <- seq(-pi, pi, len = 65)
> plot(x, sin(x), type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)
> 
> then everything works just fine.
> 
> However, if I use other data such as, for instance:
> 
> y<-c(1960, 1965, 1970, 1975)
> z<-c(1, 2, 3, 4)
> plot(y, z, type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)
> 
> then the legend is not shown.
> 
> Any hints?
> 
> Thanks in advance,
> 
> Emili
> 
> __
> R-help@stat.math.ethz.ch 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.
> 



 

Food fight? Enjoy some healthy debate

__
R-help@stat.math.ethz.ch 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 question

2007-02-28 Thread jim holtman
try:

y<-c(1960, 1965, 1970, 1975)
z<-c(1, 2, 3, 4)
plot(y, z, type="l", col = 2)
legend("topleft", "legend text", pch = 1, xjust = 0.5)



On 2/28/07, Emili Tortosa-Ausina <[EMAIL PROTECTED]> wrote:
>
> Hi to all,
>
> I'm sorry for posting this question, I am sure I am missing something
> important but after reading the documentation I cannot find where the
> problem is.
>
> I want to add a legend to a figure. If I use a simple example drawn
> from the R Reference Manual such as, for instance:
>
> x <- seq(-pi, pi, len = 65)
> plot(x, sin(x), type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)
>
> then everything works just fine.
>
> However, if I use other data such as, for instance:
>
> y<-c(1960, 1965, 1970, 1975)
> z<-c(1, 2, 3, 4)
> plot(y, z, type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)
>
> then the legend is not shown.
>
> Any hints?
>
> Thanks in advance,
>
> Emili
>
> __
> R-help@stat.math.ethz.ch 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 question

2007-02-28 Thread Jenny Barnes
Hi folks,

Do you mind if I ask a related question that I have been having trouble with - 
how do you put the legend outside of the plot area (to the bottom of the area - 
below the x-axis title)? Could anybody show me using the example given below:

x <- seq(-pi, pi, len = 65)
plot(x, sin(x), type="l", col = 2)
legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)

Thank you, I've not been able to do this simple bit of programming and it is 
very frustrating not to be able to add a simple key.

Best Wishes,

Jenny

Hi Emili,

Even though you are calling your horizontal coordinate y, and vertical
coordinate z, the first and second arguments to legend(), namely x and y,
should be the horizontal and vertical coordinates, respectively; and they are
given in user coordinates (e.g., legend()'s x should be between 1960 and 1975
and legend()'s y should be between 1 and 4).

If you want to use normalized coordinates (i.e. 0 to 1), you can scale as in
this example:

legend(x = par("usr")[1] + diff(par("usr")[1:2])*normalizedCoordX,
   y = par("usr")[3] + diff(par("usr")[3:4])*normalizedCoordY,
   ...)

where normalizedCoordX and Y go from 0 to 1 (see ?par, par("usr") returns
vector of c(xmin,xmax,ymin,ymax) of user coordinates on a plot)

You can alternatively use legend(x = "topleft",...) or "bottomright", and so
on to place your legend.

If you want to add your legend outside of the plot, you should consider
increasing the margins using the 'mar' argument in par(), and also setting
par(xpd=TRUE) (so stuff can show up outside of the plotting region).

Best regards,
ST


> y<-c(1960, 1965, 1970, 1975)
> z<-c(1, 2, 3, 4)
within the data limits of your x and y)





--- Emili Tortosa-Ausina <[EMAIL PROTECTED]> wrote:

> Hi to all,
> 
> I'm sorry for posting this question, I am sure I am missing something 
> important but after reading the documentation I cannot find where the 
> problem is.
> 
> I want to add a legend to a figure. If I use a simple example drawn 
> from the R Reference Manual such as, for instance:
> 
> x <- seq(-pi, pi, len = 65)
> plot(x, sin(x), type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)
> 
> then everything works just fine.
> 
> However, if I use other data such as, for instance:
> 
> y<-c(1960, 1965, 1970, 1975)
> z<-c(1, 2, 3, 4)
> plot(y, z, type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust = 0.5)
> 
> then the legend is not shown.
> 
> Any hints?
> 
> Thanks in advance,
> 
> Emili
> 
> __
> R-help@stat.math.ethz.ch 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.
> 



 


Food fight? Enjoy some healthy debate

__
R-help@stat.math.ethz.ch 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.

- End Forwarded Message -


~~
Jennifer Barnes
PhD student: long range drought prediction 
Climate Extremes Group
Department of Space and Climate Physics
University College London
Holmbury St Mary 
Dorking, Surrey, RH5 6NT
Tel: 01483 204149
Mob: 07916 139187
Web: http://climate.mssl.ucl.ac.uk

__
R-help@stat.math.ethz.ch 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 question

2007-02-28 Thread Sebastian P. Luque
On Wed, 28 Feb 2007 16:52:05 + (GMT),
Jenny Barnes <[EMAIL PROTECTED]> wrote:

> Hi folks, Do you mind if I ask a related question that I have been
> having trouble with - how do you put the legend outside of the plot area
> (to the bottom of the area - below the x-axis title)? Could anybody show
> me using the example given below:

> x <- seq(-pi, pi, len = 65) plot(x, sin(x), type="l", col = 2) legend(x
> = -3, y = .9, "legend text", pch = 1, xjust = 0.5)

> Thank you, I've not been able to do this simple bit of programming and
> it is very frustrating not to be able to add a simple key.

Have a look at ?par and argument 'inset' in ?legend itself.  Here's one
way:


x <- seq(-pi, pi, len=65)
par(mar=c(par("mar")[1] + 2, par("mar")[-1]))
plot(x, sin(x), type="l", col=2)
par(xpd=TRUE)
legend("bottom", "legend text", pch=1, inset=-0.3)


-- 
Seb

__
R-help@stat.math.ethz.ch 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 question

2007-03-01 Thread John Kane
? par 
it is the xpd you're looking for.

x <- seq(-pi, pi, len = 65)
par(xpd=TRUE)
plot(x, sin(x), type="l", col = 2,xpd=NA)
legend(x = 0, y = -1.5, "legend text", pch = 1, xjust
= 0.5)



--- Jenny Barnes <[EMAIL PROTECTED]> wrote:

> Hi folks,
> 
> Do you mind if I ask a related question that I have
> been having trouble with - 
> how do you put the legend outside of the plot area
> (to the bottom of the area - 
> below the x-axis title)? Could anybody show me using
> the example given below:
> 
> x <- seq(-pi, pi, len = 65)
> plot(x, sin(x), type="l", col = 2)
> legend(x = -3, y = .9, "legend text", pch = 1, xjust
> = 0.5)
> 
> Thank you, I've not been able to do this simple bit
> of programming and it is 
> very frustrating not to be able to add a simple key.
> 
> Best Wishes,
> 
> Jenny
> 
> Hi Emili,
> 
> Even though you are calling your horizontal
> coordinate y, and vertical
> coordinate z, the first and second arguments to
> legend(), namely x and y,
> should be the horizontal and vertical coordinates,
> respectively; and they are
> given in user coordinates (e.g., legend()'s x should
> be between 1960 and 1975
> and legend()'s y should be between 1 and 4).
> 
> If you want to use normalized coordinates (i.e. 0 to
> 1), you can scale as in
> this example:
> 
> legend(x = par("usr")[1] +
> diff(par("usr")[1:2])*normalizedCoordX,
>y = par("usr")[3] +
> diff(par("usr")[3:4])*normalizedCoordY,
>...)
> 
> where normalizedCoordX and Y go from 0 to 1 (see
> ?par, par("usr") returns
> vector of c(xmin,xmax,ymin,ymax) of user coordinates
> on a plot)
> 
> You can alternatively use legend(x = "topleft",...)
> or "bottomright", and so
> on to place your legend.
> 
> If you want to add your legend outside of the plot,
> you should consider
> increasing the margins using the 'mar' argument in
> par(), and also setting
> par(xpd=TRUE) (so stuff can show up outside of the
> plotting region).
> 
> Best regards,
> ST
> 
> 
> > y<-c(1960, 1965, 1970, 1975)
> > z<-c(1, 2, 3, 4)
> within the data limits of your x and y)
> 
> 
> 
> 
> 
> --- Emili Tortosa-Ausina <[EMAIL PROTECTED]>
> wrote:
> 
> > Hi to all,
> > 
> > I'm sorry for posting this question, I am sure I
> am missing something 
> > important but after reading the documentation I
> cannot find where the 
> > problem is.
> > 
> > I want to add a legend to a figure. If I use a
> simple example drawn 
> > from the R Reference Manual such as, for instance:
> > 
> > x <- seq(-pi, pi, len = 65)
> > plot(x, sin(x), type="l", col = 2)
> > legend(x = -3, y = .9, "legend text", pch = 1,
> xjust = 0.5)
> > 
> > then everything works just fine.
> > 
> > However, if I use other data such as, for
> instance:
> > 
> > y<-c(1960, 1965, 1970, 1975)
> > z<-c(1, 2, 3, 4)
> > plot(y, z, type="l", col = 2)
> > legend(x = -3, y = .9, "legend text", pch = 1,
> xjust = 0.5)
> > 
> > then the legend is not shown.
> > 
> > Any hints?
> > 
> > Thanks in advance,
> > 
> > Emili
> > 
> > __
> > R-help@stat.math.ethz.ch 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.
> > 
> 
> 
> 
>  
>

> 
> Food fight? Enjoy some healthy debate
> 
> __
> R-help@stat.math.ethz.ch 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.
> 
> - End Forwarded Message -
> 
> 
> ~~
> Jennifer Barnes
> PhD student: long range drought prediction 
> Climate Extremes Group
> Department of Space and Climate Physics
> University College London
> Holmbury St Mary 
> Dorking, Surrey, RH5 6NT
> Tel: 01483 204149
> Mob: 07916 139187
> Web: http://climate.mssl.ucl.ac.uk
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 help needed

2004-11-14 Thread Sean David Richards
R : Version 1.9.1

Hi,

Am having trouble adding a legend to scatterplot. R code is shown below. 
I have tried various incantations to add a legend (using the legend() 
function) to the resulting plot but without any success. Looks like it 
should be simple but I must be missing something. Any pointers would be 
welcome.
Have looked at help(legend) etc.

--8<--
---

sfiles <- c("72_12_12_V.csv ",
"150_25_15_V.csv",
"150_25_20_V.csv",
"150_25_25_V.csv",
"150_25_40_V.csv",
"150_25_60_V.csv",
"150_25_90_V.csv",
"240_40_40_V.csv")  

## process each file in list
for (i in 1:length(sfiles)) {
data <- read.csv(paste("../data/",sfiles[i],sep=""))

## assign columns to some nice names
K <- data[,8]
AN <- data[,3] * (data[,2] - data[,4])

## plot K against AN

if ( i == 1) {
plot(AN, K, ylim=c(1000,9000), xlim=c(0,1500), 
  xlab="Area above Notch (mm)",
  main="Size Effect Specimens")
par(new=TRUE)
}
else{
plot(AN,K, pch=(i),ylim=c(1000,9000), xlim=c(0,1500), 
  axes=FALSE,xlab="")
par(new=TRUE)
}
}

--8<--
---

-- 
Sean Richards

C-fACS
P.O. Box 84, Lincoln University,
Canterbury, New Zealand
Phone:(64)(3) 325-2811 ext 8636
Email:  [EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend Line Size

2005-03-14 Thread McGehee, Robert
Hello all,

When I view or print the below plot on my Linux machine under R 2.0.1 I
see a nice thick solid and dashed line with a legend. However, while the
lines are distinguishable, the legend is not. That is, the short (solid)
line next to "line1" and the short (dashed) line next to "line2" seem to
have the exact same length. What I would like to do is to expand the
legend line a bit farther so that the user can clearly see a solid vs. a
dashed line and not too small lines that look the same.

A glance at the legend source code shows that the line segment length
(seg.len) seems to be hard-coded as 2. If I change this to a larger
number within the code, I get the effect that I want (although the box
around the legend needs to be resized). Am I overlooking a more obvious
way to distinguish the legend lines, or would it make more sense to
patch the legend function to fit my needs?

x <- 1:10
plot(x, x, type = "l", lty = 1, lwd = 4)
lines(x, 2*x, type = "l", lty = 5, lwd = 4)
legend(7, 5, legend = c("line1", "line2"), lty = c(1, 5), lwd = 4)

Thanks,
Robert

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend as a subtitle

2005-05-20 Thread Ravi . Vishnu
Very little space is available in one of my plots for the legend. I would 
like to lift it out of the main plot area and present it in the subtitle 
area. Would appreciate any help that I can get.
Ravi Vishnu

  
This message is meant for the addressee only and may contain 
confidential and legally privileged information. Any unauthorised 
review, use, copying, storage, disclosure or distribution of this e-
mail and any attachments is strictly prohibited. If you are not the 
named recipient or have otherwise received this communication in 
error, please destroy this message from your system and kindly notify 
the sender by e-mail. Thank you for your co-operation.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend outside plotting area

2006-07-12 Thread Georg Otto
Hi,

I would like to place a legend outside a plotting area. Could anybody
give me a hint how this is done?

Cheers,

Georg

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend on trellis plot

2006-08-09 Thread Henrik Agersø

Dear all

I have two questions regarding trellis plots - which I hope you may be able to 
help me with.

Is it possible to place the key in a trellis plot on the panel (instead of 
beside the panel)? This will cause the same key to be reproduced on each panel. 
Please see the plot below - here I placed the legend below the plot. I tried 
moving the key to the function statement, but it did not really work out the 
way I expected.

One last thing, in the plot below I placed a horizontal line on the plot, is it 
possible to only have the horizontal line on the left panel (I remember that in 
S it was possible to state something like "if(get("cell",fr=9)==2)" in the 
function statement to include the line on only one of the panels)?

All suggestions will highly appreciated.

Br Henrik



###

data   <- as.data.frame(cbind(rep(1:4,each=25),
  rep(1:2,each=50) ,rep(1:25,4),
  rnorm(100,0,1) ))
names(data)   <- c("ID","DOSE","TIME","DV")



xyplot(DV~TIME | DOSE, data=data, groups=ID, layout=c(2,1),

   
key=list(space="bottom",border=TRUE,colums=2,text=list(c("ID1","ID2"),col=c(1,4)),
  lines=list(type="o",pch=c(1,16),lty=c(1,2), col=c(1,4)),
  layout.heights=list(key.axis.padding=15)),
   
   panel = function(x,y,groups,...) {
 panel.superpose.2(x,y,groups,...,type="o",pch=c(1,16),
 lty=c(1,2), col=c(1,4), cex=0.8)
 panel.abline(h=0.301,col=5,lty=1,lwd=2)  
}
)

###





[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 box line thickness

2006-08-28 Thread Phil Turk
I am merely trying to increase the line thickness, or line width, of the box 
drawn around the legend in a plot I am constructing.  The help page on 
'legend' was of no use.  Does anyone have an idea on how to do this?  Please 
respond to [EMAIL PROTECTED]  Thanks!

__
R-help@stat.math.ethz.ch 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 box line thickness

2006-08-28 Thread Philip Turk
I am making a plot and am merely trying to increase the line thickness, or
width, of the box drawn around the legend.  The help page on 'legend' was of
no use.  Does anyone have any ideas?   


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 problems in lattice

2006-09-07 Thread Ernst O Ahlberg Helgee
Hi!
Im sorry to bother you but I cant fix this.
I use the lattice function levelplot and I want the colorkey at the 
bottom, how do I get it there? I have tried changing colorkey.space and 
changing in legend but I cant get it right, plz help

btw I'd like to speceify strings to appear at the tick marks and also 
there I fail any thoughts?

cheers
Ernst

__
R-help@stat.math.ethz.ch 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 outside plotting area

2007-05-21 Thread Judith Flores
Hi, 

I have been trying many of the suggested options
to place a legend outside plotting area, including
something like this:

par(xpd=T,
oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)


But the aspect of the four plots gets compromised
when I change the margin settings. I cannot use mtext
because I need to use colors for the text. I tried
layout, but wouldn't let me include the legend, only
plots.

   I would appreciate very much some more help.

Regards,

J


   
Pinpoint
 customers who are looking for what you sell.

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-29 Thread Albert Vilella
Hi,

I have a densityplot like this:

x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
f = sample(c("A","B","C","D","E"),300,replace=TRUE)
df=data.frame(x,f)
library(lattice)
attach(df)
densityplot(~x, groups=f)

And I want to add a legend with the colours for the factors. How can I do that?
How can I not have the dots of the distribution at the bottom, or at
least, make them occupy less vertical space?

__
R-help@stat.math.ethz.ch 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 Outside Plot Dimension

2006-01-18 Thread Abd Rahman Kassim

Dear All,

I'm trying to attach a legend outside the plot (Inside plot OK), but failed. 
Any help is very much appreciated.

Thanks.


Abd. Rahman Kassim, PhD
Forest Management & Ecology Program
Forestry & Conservation Division
Forest Research Institute Malaysia
Kepong 52109 Selangor
MALAYSIA

*

Checked by TrendMicro Interscan Messaging Security.
For any enquiries, please contact FRIM IT Department.
*
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend in a HeatMap

2006-02-14 Thread Akkineni,Vasundhara
List,
 
Is it possible to add a color legend to a heatmap , similar to the one in 
levelplot and filled.contour plot. The legend will represent the colors used in 
the heatmap along with values for each color range. Can this be done? Please 
help. 
 
Thanks,
Svakki.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend on graph

2007-08-12 Thread jim holtman
If you are asking to have the values plotted on top of the legend,
then you can do the following:

plot(x, y, type='n', ...) # create plot, but don't plot
legend('topright', ...)
lines(x,y)  # now plot the data

If you want it outside the plot, check the archives for several examples.

On 8/12/07, akki <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a problem when I want to put a legend on the graph.
> I do:
>
> legend("topright", names(o), cex=0.9, col=plot_colors,lty=1:5, bty="n")
>
> but the legend is writen into the graph (graphs' top but into the graph),
> because I have values on this position. How can I write the legend on top
> the graph without the legend writes on graph's values.
>
> Thanks.
>
>[[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@stat.math.ethz.ch 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 on graph

2007-08-13 Thread Bert Gunter
You can get the legend outside the plot region by

1. First changing the clipping region via par(xpd = TRUE) ; (or xpd=NA). see
?par

2. Specifying x and y coodinates for legend placement outside the limits of
the plot region.

This allows you to include a legend without adding a bunch of useless
whitespace to the plot region; or to add a grid to the plot without
interfering with the legend.


Bert Gunter
Genentech Nonclinical Statistics


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Nguyen Dinh Nguyen
Sent: Monday, August 13, 2007 3:42 PM
To: [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Subject: [R] Legend on graph

Hi Akki, 
Then you may need to increase y-axis scale by ylim=c(min,max)
Cheers
Nguyen

On 8/12/07, akki <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a problem when I want to put a legend on the graph.
> I do:
>
> legend("topright", names(o), cex=0.9, col=plot_colors,lty=1:5, bty="n")
>
> but the legend is writen into the graph (graphs' top but into the graph),
> because I have values on this position. How can I write the legend on top
> the graph without the legend writes on graph's values.
>
> Thanks.

__
R-help@stat.math.ethz.ch 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/plotmath/substitute problem

2006-12-14 Thread Philipp Pagel

Dear R Experts,

I am trying to produce a legend for a series of plots which are
generated in a loop. The legend is supposed to look like this:

2000: gamma=1.8

where gamma is replaced by the greek letter and both the year and the
value of gamma are stored in variables.

Everything works fine as long as I have only one data series:

year = 2001
g = 1.9
plot(1)
legend('top', legend=substitute(paste(year, ': ', gamma, '=', g), 
list(year=year, g=g)) )


My problem starts, when I want to put more than one series of data in
the plot and accordingly need one legend row per data series:

year1 = 2001
year2 = 2005
g1 = 1.9
g2 = 1.7
plot(1)
legend('top', 
legend=c(
substitute(paste(year, ': ', gamma, '=', g), list(year=year1, 
g=g1)),
substitute(paste(year, ': ', gamma, '=', g), list(year=year2, 
g=g2))
)
)

This obviously does not produce the desired result. Apparently, I am not
generating a list of expressions, as intended. So I thought, maybe R uses a
variety of the recycling rule here and tried:

year = c(2001, 2005)
g = c(1.9, 1.7)
plot(1)
legend('top',
legend=list(
substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)),
)
)

No succes, either...

I have read and re-read the documentation for legend, expression, substitute
and plotmath but can't figure it out. Even drinking a cup of tea prepared from
fine-cut man page printouts didn't lead to satori.

I'm probably missing something simple. Any hints are highly appreciated.

Thanks
Philipp

-- 
Dr. Philipp PagelTel.  +49-8161-71 2131
Dept. of Genome Oriented Bioinformatics  Fax.  +49-8161-71 2186
Technical University of Munich
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@stat.math.ethz.ch 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 under plot region?

2004-07-30 Thread Jean Eid
I am trying to put legends underneath the plot (in the outer margins). Is
there an easy way to do this. I have been tinkering with split..screen but
I could not make it work.

Thank in advance

Jean

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend/Substitute/Plotmath problem

2004-10-23 Thread Johannes Graumann
Hello,

I seem unable to construct a legend which contains a substitution as
well as math symbols. I'm trying to do the following:

strain2 <- "YJG48"

legend.txt <- c(
substitute(
strain *
%==% *
"YJG45, rpn10" *
%Delta%,
list(strain=strain2)
),
"Verhulst/Logistic",
"Malthus"
)
legend(
100,2.5,
legend.txt,
cex=0.75,
bty="n",
pch=c(20,NA,NA),
lty=c(NA,1,2)

I derived this from the following "text" command which works, 

text(
160,2.2,
cex=0.5,
adj=0,
substitute(
OD[600][~nm] * 
" of 2 at " *
time2_2 *
" min" 
%~~% 
time2h_2 * 
" h",
list(
time2_2=round(time2_2,digits=0),
time2h_2=round(time2_2/60,digits=1)
)
)
)

But I can't get it to work in the context of "legend".
Any hints/ideas?

Thanks, Joh

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend placement in barplot?

2004-11-03 Thread Dan Bolser

This has been asked before, but all the answers are hidiously complex.

The

legend.text=TRUE 

option of barplot is almost exactly what I need, except I need a

legend.placement='tl'

(top left) option. This option would be in contrast to the default
placement which we could call 'tr' (top right).

Anyone know how to edit the barplot code to make this change? Could
someone like me work out how to do this?

Cheers,
Dan.

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend help needed

2004-11-15 Thread Adaikalavan Ramasamy
You have not called legend() in your codes below, so we do not know what
your problem is. See other comments below.

On Mon, 2004-11-15 at 01:08, Sean David Richards wrote:
> R : Version 1.9.1
> 
> Hi,
> 
> Am having trouble adding a legend to scatterplot. R code is shown below. 
> I have tried various incantations to add a legend (using the legend() 
> function) to the resulting plot but without any success. Looks like it 
> should be simple but I must be missing something. Any pointers would be 
> welcome.
> Have looked at help(legend) etc.

help(legend) provides many nice examples. Here is a simplified one :

x <- seq(-pi, pi, len = 65)
plot(x, sin(x), type="l", lty=1, col=1)
lines(x, cos(x), type="l", lty=2, col=2)
legend(-pi, 1, legend=c("sin", "cosine"), lty=1:2, col=1:2)

Or you can replace the last line with 
 legend(locator(1), legend=c("sin", "cosine"), lty=1:2, col=1:2)
where the legend will be placed on mouse left click.

> --8<--
> ---
> 
> sfiles <- c("72_12_12_V.csv ",
> "150_25_15_V.csv",
> "150_25_20_V.csv",
> "150_25_25_V.csv",
> "150_25_40_V.csv",
> "150_25_60_V.csv",
> "150_25_90_V.csv",
> "240_40_40_V.csv")  
> 
> ## process each file in list
> for (i in 1:length(sfiles)) {
> data <- read.csv(paste("../data/",sfiles[i],sep=""))
> 
> ## assign columns to some nice names
> K <- data[,8]
> AN <- data[,3] * (data[,2] - data[,4])
> 
> ## plot K against AN

Please give a simplified example. You do not need to show us all the
preprocessing steps. It can be distracting.

> if ( i == 1) {
> plot(AN, K, ylim=c(1000,9000), xlim=c(0,1500), 
>   xlab="Area above Notch (mm)",
>   main="Size Effect Specimens")
> par(new=TRUE)
> }
> else{
> plot(AN,K, pch=(i),ylim=c(1000,9000), xlim=c(0,1500), 
>   axes=FALSE,xlab="")
> par(new=TRUE)
> }
> }

Have you considered points() or lines() here ? You could simplify to

plot(0,1000, type="n", xlim=c(0,1500), ylim=c(1000,9000),
 xlab="Area above Notch (mm)", main="Size Effect Speciments")

n <- length(sfiles)

for (i in 1:n) {
  data <- read.csv(paste("../data/",sfiles[i],sep="")) 
  K<- data[,8]
  AN   <- data[,3] * (data[,2] - data[,4])

  points( AN, K, pch=i, col=i )
}

legend( 1500, 9000, legend=paste("Data from", sfiles), pch=1:n, col=i )

> --8<--
> ---

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend help needed

2004-11-15 Thread Adaikalavan Ramasamy
Sorry typo. The last line should read

legend(1500, 9000, legend=paste("Data from", sfiles), pch=1:n, col=1:n )
   ^^^

On Mon, 2004-11-15 at 11:39, Adaikalavan Ramasamy wrote:
> You have not called legend() in your codes below, so we do not know what
> your problem is. See other comments below.
> 
> On Mon, 2004-11-15 at 01:08, Sean David Richards wrote:
> > R : Version 1.9.1
> > 
> > Hi,
> > 
> > Am having trouble adding a legend to scatterplot. R code is shown below. 
> > I have tried various incantations to add a legend (using the legend() 
> > function) to the resulting plot but without any success. Looks like it 
> > should be simple but I must be missing something. Any pointers would be 
> > welcome.
> > Have looked at help(legend) etc.
> 
> help(legend) provides many nice examples. Here is a simplified one :
> 
> x <- seq(-pi, pi, len = 65)
> plot(x, sin(x), type="l", lty=1, col=1)
> lines(x, cos(x), type="l", lty=2, col=2)
> legend(-pi, 1, legend=c("sin", "cosine"), lty=1:2, col=1:2)
> 
> Or you can replace the last line with 
>  legend(locator(1), legend=c("sin", "cosine"), lty=1:2, col=1:2)
> where the legend will be placed on mouse left click.
> 
> > --8<--
> > ---
> > 
> > sfiles <- c("72_12_12_V.csv ",
> > "150_25_15_V.csv",
> > "150_25_20_V.csv",
> > "150_25_25_V.csv",
> > "150_25_40_V.csv",
> > "150_25_60_V.csv",
> > "150_25_90_V.csv",
> > "240_40_40_V.csv")  
> > 
> > ## process each file in list
> > for (i in 1:length(sfiles)) {
> > data <- read.csv(paste("../data/",sfiles[i],sep=""))
> > 
> > ## assign columns to some nice names
> > K <- data[,8]
> > AN <- data[,3] * (data[,2] - data[,4])
> > 
> > ## plot K against AN
> 
> Please give a simplified example. You do not need to show us all the
> preprocessing steps. It can be distracting.
> 
> > if ( i == 1) {
> > plot(AN, K, ylim=c(1000,9000), xlim=c(0,1500), 
> >   xlab="Area above Notch (mm)",
> >   main="Size Effect Specimens")
> > par(new=TRUE)
> > }
> > else{
> > plot(AN,K, pch=(i),ylim=c(1000,9000), xlim=c(0,1500), 
> >   axes=FALSE,xlab="")
> > par(new=TRUE)
> > }
> > }
> 
> Have you considered points() or lines() here ? You could simplify to
> 
> plot(0,1000, type="n", xlim=c(0,1500), ylim=c(1000,9000),
>  xlab="Area above Notch (mm)", main="Size Effect Speciments")
> 
> n <- length(sfiles)
> 
> for (i in 1:n) {
>   data <- read.csv(paste("../data/",sfiles[i],sep="")) 
>   K<- data[,8]
>   AN   <- data[,3] * (data[,2] - data[,4])
> 
>   points( AN, K, pch=i, col=i )
> }
> 
> legend( 1500, 9000, legend=paste("Data from", sfiles), pch=1:n, col=i )
> 
> > --8<--
> > ---
> 
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
-- 
Adaikalavan Ramasamy[EMAIL PROTECTED]
Centre for Statistics in Medicine   http://www.ihs.ox.ac.uk/csm/
Cancer Research UK  Tel : 01865 226 677
Old Road Campus, Headington, Oxford Fax : 01865 226 962

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend help needed

2004-11-15 Thread Sean David Richards
On 15 Nov 2004 at 12:11, Adaikalavan Ramasamy wrote:

> > Have you considered points() or lines() here ? You could simplify 
to
> > 
> > plot(0,1000, type="n", xlim=c(0,1500), ylim=c(1000,9000),
> >  xlab="Area above Notch (mm)", main="Size Effect Speciments")
> > 
> > n <- length(sfiles)
> > 
> > for (i in 1:n) {
> >   data <- read.csv(paste("../data/",sfiles[i],sep="")) 
> >   K<- data[,8]
> >   AN   <- data[,3] * (data[,2] - data[,4])
> > 
> >   points( AN, K, pch=i, col=i )
> > }
> > 
> > legend( 1500, 9000, legend=paste("Data from", sfiles), pch=1:n, 
col=i:n)

Thanks this got me going on the right track. The code is a lot more 
concise as well :) 
Using locator() instead of x,y coord was suggested by Tom and that 
showed me where my problem was. The legend was being created just not 
where it would be visible.
I found this bit of code in the R-help archives and it makes thing a 
lot more straightforward when positioning a legend

## set the range of the usr coordinates to x = (0,1), y = (0,1) 
opar <- par(no.readonly=TRUE) 
par(usr=c(0,1,0,1)) 

## add the legend
legend(0.75,0.9,sub(".csv","",nfiles), pch=1:length(nfiles), cex=0.7)

Cheers

-- 
Sean Richards

C-fACS
P.O. Box 84, Lincoln University,
Canterbury, New Zealand
Phone:(64)(3) 325-2811 ext 8636
Email:  [EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend position in barplots

2003-11-16 Thread Andreas Lackner
Hello!



Is there a way to change the position of the legend created in a barplot
from the right side of the plot to the left side or somewhere else?

Thanks

 

 

 

 

 

 

 

 

Dipl.-Kfm. Andreas Lackner

 

Universität Göttingen

Institut für Wirtschaftsinformatik, Abtl. I

Prof. Dr. Jörg Biethahn

Platz der Göttinger Sieben 5

37073 Göttingen

 

Zimmer: 1709, Spr.-Std: Di. 10-11

Tel: (0551) 39-8415

Fax: (0551) 39-9679

URL: http://www.wi1.wiso.uni-goettingen.de/mm/alackne/index.htm  

 


[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Legend Line Size

2005-03-14 Thread Marc Schwartz
On Mon, 2005-03-14 at 15:55 -0500, McGehee, Robert wrote:
> Hello all,
> 
> When I view or print the below plot on my Linux machine under R 2.0.1 I
> see a nice thick solid and dashed line with a legend. However, while the
> lines are distinguishable, the legend is not. That is, the short (solid)
> line next to "line1" and the short (dashed) line next to "line2" seem to
> have the exact same length. What I would like to do is to expand the
> legend line a bit farther so that the user can clearly see a solid vs. a
> dashed line and not too small lines that look the same.
> 
> A glance at the legend source code shows that the line segment length
> (seg.len) seems to be hard-coded as 2. If I change this to a larger
> number within the code, I get the effect that I want (although the box
> around the legend needs to be resized). Am I overlooking a more obvious
> way to distinguish the legend lines, or would it make more sense to
> patch the legend function to fit my needs?
> 
> x <- 1:10
> plot(x, x, type = "l", lty = 1, lwd = 4)
> lines(x, 2*x, type = "l", lty = 5, lwd = 4)
> legend(7, 5, legend = c("line1", "line2"), lty = c(1, 5), lwd = 4)

Robert,

I think that this is exhibiting an interaction between the line type and
the line width. 

I have not looked at the low level segments code to see what is going
on, but if you try 'lwd = 2' in the call to legend, the dashed line
shows up fine. If I try a line width of 3, it seems that this is the
point where there is the loss of the dashed line type.

There is a difference in the appearance of the line even with a lwd
setting of 1 versus 2.

I temporarily put up a PDF file at:

http://www.MedAnalytics.com/Rplots.pdf

The lwd setting in each plot is:

1, 2
3, 4

You can see the progression of the loss of the dashed line type in the
lower two plots. It appears as if the length of the first dash increases
as the line width increases, rather than just the line width increasing
independently. So there is a progressive loss of the second dash.
resulting in a single solid line.

Not sure if that helps, but if you can stay with 'lwd = 1' for your
plot, that should solve the problem.

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend issue with ggplot2

2007-09-03 Thread ONKELINX, Thierry
Dear useRs,

I'm struggling with the new version of ggplot2. In the previous version
I did something like this. But now this yield an error (object "fill"
not found).

library(ggplot2)
dummy <- data.frame(x = rep(1:10, 4), group = gl(4, 10))
dummy$y <- dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group]
dummy$min <- dummy$y - 5
dummy$max <- dummy$y + 5
ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) +
geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y
= min, colour = fill))

When I adjust the code to the line below, it works again. But this time
with two legend keys for "group". Any idea how to display only one
legend key for group? The ggplot-code aboved yielded only on legend key.

ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group,
fill = group)) + geom_ribbon() + geom_line(aes(y = max)) +
geom_line(aes(y = min))

Thanks,

Thierry



ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[EMAIL PROTECTED]
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

__
R-help@stat.math.ethz.ch 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 as a subtitle

2005-05-20 Thread Uwe Ligges
[EMAIL PROTECTED] wrote:
Very little space is available in one of my plots for the legend. I would 
like to lift it out of the main plot area and present it in the subtitle 
area. Would appreciate any help that I can get.
Look at the following code and read the corresponding help pages:
 plot(1:10, xlab="")
 ## clipping to device region rather than plot region:
 par(xpd=NA)
 legend(mean(par("usr")[1:2]), 0,
   legend="nonsense", xjust=0.5)
Uwe Ligges

Ravi Vishnu
  
This message is meant for the addressee only and may contain 
confidential and legally privileged information. Any unauthorised 
review, use, copying, storage, disclosure or distribution of this e-
mail and any attachments is strictly prohibited. If you are not the 
named recipient or have otherwise received this communication in 
error, please destroy this message from your system and kindly notify 
the sender by e-mail. Thank you for your co-operation.

[[alternative HTML version deleted]]
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend title in effects plot

2006-06-22 Thread Viktor Tron
Could someone tell how I can change/remove the legend title in a
(multiline) effects plot?
Thanks
V

This is virtually a resubmission of
https://stat.ethz.ch/pipermail/r-help/2006-May/106340.html


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] legend outside plotting area

2006-07-12 Thread Joris De Wolf
see
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/68585.html

Georg Otto wrote:
> Hi,
> 
> I would like to place a legend outside a plotting area. Could anybody
> give me a hint how this is done?
> 
> Cheers,
> 
> Georg
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


confidentiality notice:
The information contained in this e-mail is confidential and...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] legend on trellis plot

2006-08-09 Thread Gabor Grothendieck
1. Use the x, y and corner components to the key= list to specify
the legend position, and
2. pass the panel.number in the panel function and test that as shown
in the panel function below.
Alternately you can place the horizontal line on afterwards using
trellis.focus/trellis.unfocus as shown below.

Read the material under key= and panel= in ?xyplot for more information
on the key and panel arguments and read ?trellis.focus for more
information on trellis.focus/trellis.unfocus.


xyplot(DV~TIME | DOSE, data=data, groups=ID, layout=c(2,1),
  
key=list(x=.1,y=.8,corner=c(0,0),border=TRUE,colums=2,text=list(c("ID1","ID2"),col=c(1,4)),
 lines=list(type="o",pch=c(1,16),lty=c(1,2), col=c(1,4)),
 layout.heights=list(key.axis.padding=15)),

  panel = function(x,y,groups,...,panel.number) {
panel.superpose.2(x,y,groups,...,type="o",pch=c(1,16),
lty=c(1,2), col=c(1,4), cex=0.8)
if (panel.number == 1) panel.abline(h=0.301,col=5,lty=1,lwd=2)
   }
)


# add a red horizontal line only to panel 2, 1
trellis.focus("panel", 2, 1, highlight = FALSE)
panel.abline(h=0.301,col=2,lty=1,lwd=2)
trellis.unfocus()


On 8/9/06, HKAG (Henrik Agersø) <[EMAIL PROTECTED]> wrote:
>
> Dear all
>
> I have two questions regarding trellis plots - which I hope you may be able 
> to help me with.
>
> Is it possible to place the key in a trellis plot on the panel (instead of 
> beside the panel)? This will cause the same key to be reproduced on each 
> panel. Please see the plot below - here I placed the legend below the plot. I 
> tried moving the key to the function statement, but it did not really work 
> out the way I expected.
>
> One last thing, in the plot below I placed a horizontal line on the plot, is 
> it possible to only have the horizontal line on the left panel (I remember 
> that in S it was possible to state something like "if(get("cell",fr=9)==2)" 
> in the function statement to include the line on only one of the panels)?
>
> All suggestions will highly appreciated.
>
> Br Henrik
>
>
>
> ###
>
> data   <- as.data.frame(cbind(rep(1:4,each=25),
>  rep(1:2,each=50) ,rep(1:25,4),
>  rnorm(100,0,1) ))
> names(data)   <- c("ID","DOSE","TIME","DV")
>
>
>
> xyplot(DV~TIME | DOSE, data=data, groups=ID, layout=c(2,1),
>
>   
> key=list(space="bottom",border=TRUE,colums=2,text=list(c("ID1","ID2"),col=c(1,4)),
>  lines=list(type="o",pch=c(1,16),lty=c(1,2), col=c(1,4)),
>  layout.heights=list(key.axis.padding=15)),
>
>   panel = function(x,y,groups,...) {
> panel.superpose.2(x,y,groups,...,type="o",pch=c(1,16),
> lty=c(1,2), col=c(1,4), cex=0.8)
> panel.abline(h=0.301,col=5,lty=1,lwd=2)
>}
> )
>
> ###
>
>
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 box line thickness

2006-08-28 Thread Marc Schwartz
On Mon, 2006-08-28 at 17:55 -0700, Phil Turk wrote:
> I am merely trying to increase the line thickness, or line width, of the box 
> drawn around the legend in a plot I am constructing.  The help page on 
> 'legend' was of no use.  Does anyone have an idea on how to do this?  Please 
> respond to [EMAIL PROTECTED]  Thanks!

There are two options.

The easier one is not immediately evident from the help page and
requires reviewing the R code for the legend function, which reveals
that there is an internal function called rect2(), which is built on top
of rect(). It is this function that draws the outer box.

The help page for rect() shows that the line width argument 'lwd' in the
function defaults to par("lwd"). See ?par for more information.

Thus using:

  par(lwd = SomethingGreaterThan1)

before the call to legend will set the box to a wider line thickness.

Be sure to set par(lwd = 1) before any other plot calls to return to the
default setting.



Second, the Value section of ?legend clearly indicates:


Value

A list with list components

rect
a list with components 
w, h
positive numbers giving
width and height of the
legend's box.
left, top
x and y coordinates of upper
left corner of the box.
text
a list with components 
x, y
numeric vectors of length
length(legend), giving the x
and y coordinates of the
legend's text(s).

returned invisibly.



Thus, expanding on the third example in ?legend:

## right-justifying a set of labels: thanks to Uwe Ligges
x <- 1:5; y1 <- 1/x; y2 <- 2/x
plot(rep(x, 2), c(y1, y2), type="n", xlab="x", ylab="y")
lines(x, y1); lines(x, y2, lty=2)

# Key call here
temp <- legend("topright", legend = c(" ", " "),
   text.width = strwidth("1,000,000"),
   lty = 1:2, xjust = 1, yjust = 1,
   title = "Line Types")

text(temp$rect$left + temp$rect$w, temp$text$y,
 c("1,000", "1,000,000"), pos=2)


# Now do the legend box using a wide line:
rect(temp$rect$left, temp$rect$top - temp$rect$h, 
 temp$rect$left + temp$rect$w, temp$rect$top + temp$rect$h, lwd = 2)


It would not seem unreasonable to add new arguments to legend(), perhaps
calling them box.lwd and box.lty, which can then be passed to the
rect2() internal function call for the box by modifying the existing
call to:

 rect2(left, top, dx = w, dy = h, col = bg, density = NULL, 
   lwd = box.lwd, lty = box.lty)


HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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 problems in lattice

2006-09-07 Thread Sundar Dorai-Raj


Ernst O Ahlberg Helgee wrote:
> Hi!
> Im sorry to bother you but I cant fix this.
> I use the lattice function levelplot and I want the colorkey at the 
> bottom, how do I get it there? I have tried changing colorkey.space and 
> changing in legend but I cant get it right, plz help
> 
> btw I'd like to speceify strings to appear at the tick marks and also 
> there I fail any thoughts?
> 
> cheers
> Ernst
> 
> __
> R-help@stat.math.ethz.ch 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.

Hi, Ernst,

Please read ?levelplot. Under the argument for "colorkey" you will see:

colorkey: logical specifying whether a color key is to be drawn
   alongside the plot, or a list describing the color key. The
   list may contain the following components:


   'space': location of the colorkey, can be one of '"left"',
'"right"', '"top"' and '"bottom"'.  Defaults to
'"right"'.


So the answer to your first question is:

levelplot(..., colorkey = list(space = "bottom"))

For your second question, use the "scale" argument. See ?xyplot for 
details. For example,

levelplot(..., scale = list(x = list(at = 1:4, labels = letters[1:4])))

HTH,

--sundar

__
R-help@stat.math.ethz.ch 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 out of Plot Region

2005-09-24 Thread Michel Friesenhahn

Hi,

Could someone tell me how to place a legend outside the plot region?

Thanks,

Mike

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend with density and fill

2007-03-17 Thread Simon Pickett
Hi,

I am trying to make a legend with four symbols as follows

1.white box
2.black box
3.clear box (same as background)
4.clear box with shading lines

but the shading lines arent showing...

here is my code.

par(bg="lightyellow")
barplot(c(seq(1,6,1)))
legend(8.5,0.3, bty="o", legend=c("young","old","male","female"),
col="black",cex=1.5,
fill=c("white","dark grey",0,0),density=c(NA,NA,0,100),angle=45)

any suggestions much appreciated,
Thanks, Simon.



Simon Pickett
PhD student
Centre For Ecology and Conservation
Tremough Campus
University of Exeter in Cornwall
TR109EZ
Tel 01326371852

__
R-help@stat.math.ethz.ch 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 outside plotting area

2007-05-22 Thread Vladimir Eremeev

RSiteSearch("legend outside plot") 
will bring you many links to the discussions of this question.

layout perfectly allows everything.
typical sequence looks like this

This divides the device region by two parts one below another:
layout(matrix(c(1,2),byrow=TRUE), heights=[blah-blah-blah], [some other
arguments])

Then we plot on the first part:
plot( ...  )
lines ( ... )
points ( ... )
grid( ... )
  [ whatever you want on the plotting area] 

Then we finish plotting on the first part of the layout matrix and come to
the next, legend part.
The only thing to do is placing the legend in the top left corner.
plot.new(); 
plot.window(c(0,1), c(0,1));

legend(0,1, [ legend text ] )


Judith Flores wrote:
> 
> Hi, 
> 
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
> 
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
> 
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
> 
>I would appreciate very much some more help.
> 
> Regards,
> 
> J
> 

-- 
View this message in context: 
http://www.nabble.com/Legend-outside-plotting-area-tf3794564.html#a10735956
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch 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 outside plotting area

2007-05-22 Thread Carsten Jaeger
Judith,

you might try split.screen() and related functions, see ?screen.

Example:
split.screen(c(1,2)) # 1 row, 2 columns
split.screen(c(2,2), screen = 1) # split left column into 2x2
for(i in 3:6) { screen(i); plot(1:10) }
screen(2)
plot(1, type="n", axes=F, ann=F) # empty plot
legend("center", pch=1, legend="Data")


Regards,

Carsten

> Hi, 
> 
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
> 
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
> 
> 
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
> 
>I would appreciate very much some more help.
> 
> Regards,
> 
> J

__
R-help@stat.math.ethz.ch 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 outside plotting area

2007-05-23 Thread J . delasHeras
Quoting Judith Flores <[EMAIL PROTECTED]>:

> Hi,
>
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
>
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
>
>
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
>
>I would appreciate very much some more help.
>
> Regards,
>
> J

you can use 'mtext' with colors...

mtext("whatever", col="blue"...)

-- 
Dr. Jose I. de las Heras  Email: [EMAIL PROTECTED]
The Wellcome Trust Centre for Cell BiologyPhone: +44 (0)131 6513374
Institute for Cell & Molecular BiologyFax:   +44 (0)131 6507360
Swann Building, Mayfield Road
University of Edinburgh
Edinburgh EH9 3JR
UK

__
R-help@stat.math.ethz.ch 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 outside plotting area

2007-05-29 Thread S Ellison
Judith,

Haven't tried it in anger myself, but two things suggest themselves. The first 
is to use the lattice package, which seems to draw keys (autokey option) 
outside the plot region by default. Look at the last couple of examples in 
?xyplot. May save a lot of hassle...

In classical R graphics, have you tried plotting everything explicitly inside a 
plot region with margins at zero? 

For example:
plot.new()
par(mar=c(0,0,0,0))
plot.window(xlim=c(-2,11), ylim=c(-3,13))
points(1:10,1:10, pch=1)
points(1:10,10:1, pch=19)
par(srt=90)
text(x=-2, y=5, "y-axis", pos=1, offset=0.5)
par(srt=0)
text(c(5,5), c(13,-1), labels=c("Title","x-axis"), pos=1, offset=0.7, 
cex=c(1.5,1))
rect(-0.2,-0.2, 11.2,11.2)
axis(side=1, at=0:10, pos=-0.2)
axis(side=2, at=0:10, pos=-0.2)
legend(x=5, y=-2, xjust=0.5, pch=c(1,19), legend=c("Type 1", "Type 19"), ncol=2)

All very tedious, but it works. Also, fiddling around with things like pretty() 
on the data can automate most of the above positional choices if you're so 
inclined. And legend(..., plot=F) returns the legend size and coordinates if 
you want to fine-tune the location.

Steve E

>>> <[EMAIL PROTECTED]> 23/05/2007 13:14:54 >>>
Quoting Judith Flores <[EMAIL PROTECTED]>:

> Hi,
>
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
>
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
>
>
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
>
>I would appreciate very much some more help.
>
> Regards,
>
> J


***
This email and any attachments are confidential. Any use, co...{{dropped}}

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-29 Thread Chuck Cleland
Albert Vilella wrote:
> Hi,
> 
> I have a densityplot like this:
> 
> x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> df=data.frame(x,f)
> library(lattice)
> attach(df)
> densityplot(~x, groups=f)
> 
> And I want to add a legend with the colours for the factors. How can I do 
> that?
> How can I not have the dots of the distribution at the bottom, or at
> least, make them occupy less vertical space?

  Change the last line to the following:

densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)

See ?panel.densityplot .

> __
> R-help@stat.math.ethz.ch 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.
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-29 Thread Albert Vilella
Are this legend colors correlated to the plot?

If I do a:

densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5))

I get different colors in the legend than the plot...


On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> Albert Vilella wrote:
> > Hi,
> >
> > I have a densityplot like this:
> >
> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> > df=data.frame(x,f)
> > library(lattice)
> > attach(df)
> > densityplot(~x, groups=f)
> >
> > And I want to add a legend with the colours for the factors. How can I do 
> > that?
> > How can I not have the dots of the distribution at the bottom, or at
> > least, make them occupy less vertical space?
>
>   Change the last line to the following:
>
> densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
>
> See ?panel.densityplot .
>
> > __
> > R-help@stat.math.ethz.ch 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.
> >
>
> --
> Chuck Cleland, Ph.D.
> NDRI, Inc.
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 512-0171 (M, W, F)
> fax: (917) 438-0894
>

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-29 Thread Gabor Grothendieck
Try specifying it at the par.settings= level since that is where both
the plot and the legend get it from:

set.seed(1)
DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
f = sample(c("A","B","C","D","E"),300,replace=TRUE))
library(lattice)
densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
 par.settings = list(superpose.line = list(col = heat.colors(5


On 11/29/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> Are this legend colors correlated to the plot?
>
> If I do a:
>
> densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5))
>
> I get different colors in the legend than the plot...
>
>
> On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > Albert Vilella wrote:
> > > Hi,
> > >
> > > I have a densityplot like this:
> > >
> > > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> > > df=data.frame(x,f)
> > > library(lattice)
> > > attach(df)
> > > densityplot(~x, groups=f)
> > >
> > > And I want to add a legend with the colours for the factors. How can I do 
> > > that?
> > > How can I not have the dots of the distribution at the bottom, or at
> > > least, make them occupy less vertical space?
> >
> >   Change the last line to the following:
> >
> > densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
> >
> > See ?panel.densityplot .
> >
> > > __
> > > R-help@stat.math.ethz.ch 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.
> > >
> >
> > --
> > Chuck Cleland, Ph.D.
> > NDRI, Inc.
> > 71 West 23rd Street, 8th floor
> > New York, NY 10010
> > tel: (212) 845-4495 (Tu, Th)
> > tel: (732) 512-0171 (M, W, F)
> > fax: (917) 438-0894
> >
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 in lattice densityplot

2006-11-29 Thread Chuck Cleland
Albert Vilella wrote:
> Are this legend colors correlated to the plot?

  They are if you rely on the colors in

trellis.par.get("superpose.line")$col

  If you want different colors you might use trellis.par.set() to
temporarily change the colors:

x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
f <- rep(c("A","B","C"), each=100)
df <- data.frame(x,f)
library(lattice)

oldpar <- trellis.par.get("superpose.line")$col

trellis.par.set(superpose.line = list(col = heat.colors(3)))

densityplot(~ x, groups = f, data = df,
 plot.points=FALSE,
 auto.key=TRUE)

trellis.par.set(superpose.line = list(col = oldpar))

  If you don't require points or lines in the key, you also could do
something like this:

densityplot(~ x, groups = f, data = df,
 plot.points=FALSE,
 key = simpleKey(levels(df$f),
 lines=FALSE,
 points=FALSE,
 col=heat.colors(3)),
 col=heat.colors(3))

  To use your own colors without changing the trellis settings and to
get lines or points in the key, you probably need at least to use key =
simpleKey() rather than the auto.key argument, and you may need to look
into draw.key().  Other people on the list might know simpler approaches
for using your own colors in this situation.

> If I do a:
> 
> densityplot(~x, groups=f, plot.points=FALSE,
> auto.key=TRUE,col=heat.colors(5))
> 
> I get different colors in the legend than the plot...
> 
> 
> On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
>> Albert Vilella wrote:
>> > Hi,
>> >
>> > I have a densityplot like this:
>> >
>> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
>> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
>> > df=data.frame(x,f)
>> > library(lattice)
>> > attach(df)
>> > densityplot(~x, groups=f)
>> >
>> > And I want to add a legend with the colours for the factors. How can
>> I do that?
>> > How can I not have the dots of the distribution at the bottom, or at
>> > least, make them occupy less vertical space?
>>
>>   Change the last line to the following:
>>
>> densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
>>
>> See ?panel.densityplot .
>>
>> > __
>> > R-help@stat.math.ethz.ch 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.
>> >
>>
>> -- 
>> Chuck Cleland, Ph.D.
>> NDRI, Inc.
>> 71 West 23rd Street, 8th floor
>> New York, NY 10010
>> tel: (212) 845-4495 (Tu, Th)
>> tel: (732) 512-0171 (M, W, F)
>> fax: (917) 438-0894
>>
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-30 Thread Albert Vilella
Can I combine colors and line types? For example, would it be possible
to have 5 colors per 2 types of lines (continuous and dashed)?

On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> Albert Vilella wrote:
> > Are this legend colors correlated to the plot?
>
>   They are if you rely on the colors in
>
> trellis.par.get("superpose.line")$col
>
>   If you want different colors you might use trellis.par.set() to
> temporarily change the colors:
>
> x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
> f <- rep(c("A","B","C"), each=100)
> df <- data.frame(x,f)
> library(lattice)
>
> oldpar <- trellis.par.get("superpose.line")$col
>
> trellis.par.set(superpose.line = list(col = heat.colors(3)))
>
> densityplot(~ x, groups = f, data = df,
>  plot.points=FALSE,
>  auto.key=TRUE)
>
> trellis.par.set(superpose.line = list(col = oldpar))
>
>   If you don't require points or lines in the key, you also could do
> something like this:
>
> densityplot(~ x, groups = f, data = df,
>  plot.points=FALSE,
>  key = simpleKey(levels(df$f),
>  lines=FALSE,
>  points=FALSE,
>  col=heat.colors(3)),
>  col=heat.colors(3))
>
>   To use your own colors without changing the trellis settings and to
> get lines or points in the key, you probably need at least to use key =
> simpleKey() rather than the auto.key argument, and you may need to look
> into draw.key().  Other people on the list might know simpler approaches
> for using your own colors in this situation.
>
> > If I do a:
> >
> > densityplot(~x, groups=f, plot.points=FALSE,
> > auto.key=TRUE,col=heat.colors(5))
> >
> > I get different colors in the legend than the plot...
> >
> >
> > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> >> Albert Vilella wrote:
> >> > Hi,
> >> >
> >> > I have a densityplot like this:
> >> >
> >> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> >> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> >> > df=data.frame(x,f)
> >> > library(lattice)
> >> > attach(df)
> >> > densityplot(~x, groups=f)
> >> >
> >> > And I want to add a legend with the colours for the factors. How can
> >> I do that?
> >> > How can I not have the dots of the distribution at the bottom, or at
> >> > least, make them occupy less vertical space?
> >>
> >>   Change the last line to the following:
> >>
> >> densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
> >>
> >> See ?panel.densityplot .
> >>
> >> > __
> >> > R-help@stat.math.ethz.ch 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.
> >> >
> >>
> >> --
> >> Chuck Cleland, Ph.D.
> >> NDRI, Inc.
> >> 71 West 23rd Street, 8th floor
> >> New York, NY 10010
> >> tel: (212) 845-4495 (Tu, Th)
> >> tel: (732) 512-0171 (M, W, F)
> >> fax: (917) 438-0894
> >>
> >
>
> --
> Chuck Cleland, Ph.D.
> NDRI, Inc.
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 512-0171 (M, W, F)
> fax: (917) 438-0894
>

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-30 Thread Chuck Cleland
Albert Vilella wrote:
> Can I combine colors and line types? For example, would it be possible
> to have 5 colors per 2 types of lines (continuous and dashed)?

  Yes.  Using Gabor's suggestion of changing the trellis settings within
the call to densityplot(), try something like this:

x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
f <- rep(c("A","B","C"), each=100)
df <- data.frame(x,f)
library(lattice)

densityplot(~ x, groups = f, data = df,
 plot.points=FALSE,
 auto.key=TRUE,
 par.settings = list(superpose.line = list(col =
c("Green", "Red", "Blue"), lty=c(2,1,2

> On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
>> Albert Vilella wrote:
>>> Are this legend colors correlated to the plot?
>>   They are if you rely on the colors in
>>
>> trellis.par.get("superpose.line")$col
>>
>>   If you want different colors you might use trellis.par.set() to
>> temporarily change the colors:
>>
>> x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
>> f <- rep(c("A","B","C"), each=100)
>> df <- data.frame(x,f)
>> library(lattice)
>>
>> oldpar <- trellis.par.get("superpose.line")$col
>>
>> trellis.par.set(superpose.line = list(col = heat.colors(3)))
>>
>> densityplot(~ x, groups = f, data = df,
>>  plot.points=FALSE,
>>  auto.key=TRUE)
>>
>> trellis.par.set(superpose.line = list(col = oldpar))
>>
>>   If you don't require points or lines in the key, you also could do
>> something like this:
>>
>> densityplot(~ x, groups = f, data = df,
>>  plot.points=FALSE,
>>  key = simpleKey(levels(df$f),
>>  lines=FALSE,
>>  points=FALSE,
>>  col=heat.colors(3)),
>>  col=heat.colors(3))
>>
>>   To use your own colors without changing the trellis settings and to
>> get lines or points in the key, you probably need at least to use key =
>> simpleKey() rather than the auto.key argument, and you may need to look
>> into draw.key().  Other people on the list might know simpler approaches
>> for using your own colors in this situation.
>>
>>> If I do a:
>>>
>>> densityplot(~x, groups=f, plot.points=FALSE,
>>> auto.key=TRUE,col=heat.colors(5))
>>>
>>> I get different colors in the legend than the plot...
>>>
>>>
>>> On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
 Albert Vilella wrote:
> Hi,
>
> I have a densityplot like this:
>
> x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> df=data.frame(x,f)
> library(lattice)
> attach(df)
> densityplot(~x, groups=f)
>
> And I want to add a legend with the colours for the factors. How can
 I do that?
> How can I not have the dots of the distribution at the bottom, or at
> least, make them occupy less vertical space?
   Change the last line to the following:

 densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)

 See ?panel.densityplot .

> __
> R-help@stat.math.ethz.ch 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.
>
 --
 Chuck Cleland, Ph.D.
 NDRI, Inc.
 71 West 23rd Street, 8th floor
 New York, NY 10010
 tel: (212) 845-4495 (Tu, Th)
 tel: (732) 512-0171 (M, W, F)
 fax: (917) 438-0894

>> --
>> Chuck Cleland, Ph.D.
>> NDRI, Inc.
>> 71 West 23rd Street, 8th floor
>> New York, NY 10010
>> tel: (212) 845-4495 (Tu, Th)
>> tel: (732) 512-0171 (M, W, F)
>> fax: (917) 438-0894
>>
> 
> __
> R-help@stat.math.ethz.ch 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.
> 
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-30 Thread Gabor Grothendieck
Yes  by using the lty suboption of superpose.line.
Here is a modification of the prior example to illustrate:
We also use lwd as well in this example.

set.seed(1)
DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
   f = sample(c("A","B","C","D","E"),300,replace=TRUE))
library(lattice)
densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
 par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2,
 lwd = c(1,1,1,1,2


On 11/30/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> Can I combine colors and line types? For example, would it be possible
> to have 5 colors per 2 types of lines (continuous and dashed)?
>
> On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > Albert Vilella wrote:
> > > Are this legend colors correlated to the plot?
> >
> >   They are if you rely on the colors in
> >
> > trellis.par.get("superpose.line")$col
> >
> >   If you want different colors you might use trellis.par.set() to
> > temporarily change the colors:
> >
> > x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
> > f <- rep(c("A","B","C"), each=100)
> > df <- data.frame(x,f)
> > library(lattice)
> >
> > oldpar <- trellis.par.get("superpose.line")$col
> >
> > trellis.par.set(superpose.line = list(col = heat.colors(3)))
> >
> > densityplot(~ x, groups = f, data = df,
> >  plot.points=FALSE,
> >  auto.key=TRUE)
> >
> > trellis.par.set(superpose.line = list(col = oldpar))
> >
> >   If you don't require points or lines in the key, you also could do
> > something like this:
> >
> > densityplot(~ x, groups = f, data = df,
> >  plot.points=FALSE,
> >  key = simpleKey(levels(df$f),
> >  lines=FALSE,
> >  points=FALSE,
> >  col=heat.colors(3)),
> >  col=heat.colors(3))
> >
> >   To use your own colors without changing the trellis settings and to
> > get lines or points in the key, you probably need at least to use key =
> > simpleKey() rather than the auto.key argument, and you may need to look
> > into draw.key().  Other people on the list might know simpler approaches
> > for using your own colors in this situation.
> >
> > > If I do a:
> > >
> > > densityplot(~x, groups=f, plot.points=FALSE,
> > > auto.key=TRUE,col=heat.colors(5))
> > >
> > > I get different colors in the legend than the plot...
> > >
> > >
> > > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > >> Albert Vilella wrote:
> > >> > Hi,
> > >> >
> > >> > I have a densityplot like this:
> > >> >
> > >> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > >> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> > >> > df=data.frame(x,f)
> > >> > library(lattice)
> > >> > attach(df)
> > >> > densityplot(~x, groups=f)
> > >> >
> > >> > And I want to add a legend with the colours for the factors. How can
> > >> I do that?
> > >> > How can I not have the dots of the distribution at the bottom, or at
> > >> > least, make them occupy less vertical space?
> > >>
> > >>   Change the last line to the following:
> > >>
> > >> densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
> > >>
> > >> See ?panel.densityplot .
> > >>
> > >> > __
> > >> > R-help@stat.math.ethz.ch 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.
> > >> >
> > >>
> > >> --
> > >> Chuck Cleland, Ph.D.
> > >> NDRI, Inc.
> > >> 71 West 23rd Street, 8th floor
> > >> New York, NY 10010
> > >> tel: (212) 845-4495 (Tu, Th)
> > >> tel: (732) 512-0171 (M, W, F)
> > >> fax: (917) 438-0894
> > >>
> > >
> >
> > --
> > Chuck Cleland, Ph.D.
> > NDRI, Inc.
> > 71 West 23rd Street, 8th floor
> > New York, NY 10010
> > tel: (212) 845-4495 (Tu, Th)
> > tel: (732) 512-0171 (M, W, F)
> > fax: (917) 438-0894
> >
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 in lattice densityplot

2006-11-30 Thread Albert Vilella
Should it be a problem to print this dashed line plots as svgs?

library(RSvgDevice)
devSVG(file = "/home/avilella/file01.svg",
   width = 20, height = 16, bg = "white", fg = "black", onefile=TRUE,
   xmlHeader=TRUE)
densityplot(...)
dev.off()

I am getting all the lines as continuous, not dashed...

On 11/30/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> Yes  by using the lty suboption of superpose.line.
> Here is a modification of the prior example to illustrate:
> We also use lwd as well in this example.
>
> set.seed(1)
> DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
>f = sample(c("A","B","C","D","E"),300,replace=TRUE))
> library(lattice)
> densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
>  par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2,
>  lwd = c(1,1,1,1,2
>
>
> On 11/30/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> > Can I combine colors and line types? For example, would it be possible
> > to have 5 colors per 2 types of lines (continuous and dashed)?
> >
> > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > > Albert Vilella wrote:
> > > > Are this legend colors correlated to the plot?
> > >
> > >   They are if you rely on the colors in
> > >
> > > trellis.par.get("superpose.line")$col
> > >
> > >   If you want different colors you might use trellis.par.set() to
> > > temporarily change the colors:
> > >
> > > x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
> > > f <- rep(c("A","B","C"), each=100)
> > > df <- data.frame(x,f)
> > > library(lattice)
> > >
> > > oldpar <- trellis.par.get("superpose.line")$col
> > >
> > > trellis.par.set(superpose.line = list(col = heat.colors(3)))
> > >
> > > densityplot(~ x, groups = f, data = df,
> > >  plot.points=FALSE,
> > >  auto.key=TRUE)
> > >
> > > trellis.par.set(superpose.line = list(col = oldpar))
> > >
> > >   If you don't require points or lines in the key, you also could do
> > > something like this:
> > >
> > > densityplot(~ x, groups = f, data = df,
> > >  plot.points=FALSE,
> > >  key = simpleKey(levels(df$f),
> > >  lines=FALSE,
> > >  points=FALSE,
> > >  col=heat.colors(3)),
> > >  col=heat.colors(3))
> > >
> > >   To use your own colors without changing the trellis settings and to
> > > get lines or points in the key, you probably need at least to use key =
> > > simpleKey() rather than the auto.key argument, and you may need to look
> > > into draw.key().  Other people on the list might know simpler approaches
> > > for using your own colors in this situation.
> > >
> > > > If I do a:
> > > >
> > > > densityplot(~x, groups=f, plot.points=FALSE,
> > > > auto.key=TRUE,col=heat.colors(5))
> > > >
> > > > I get different colors in the legend than the plot...
> > > >
> > > >
> > > > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > > >> Albert Vilella wrote:
> > > >> > Hi,
> > > >> >
> > > >> > I have a densityplot like this:
> > > >> >
> > > >> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > > >> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> > > >> > df=data.frame(x,f)
> > > >> > library(lattice)
> > > >> > attach(df)
> > > >> > densityplot(~x, groups=f)
> > > >> >
> > > >> > And I want to add a legend with the colours for the factors. How can
> > > >> I do that?
> > > >> > How can I not have the dots of the distribution at the bottom, or at
> > > >> > least, make them occupy less vertical space?
> > > >>
> > > >>   Change the last line to the following:
> > > >>
> > > >> densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
> > > >>
> > > >> See ?panel.densityplot .
> > > >>
> > > >> > __
> > > >> > R-help@stat.math.ethz.ch 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.
> > > >> >
> > > >>
> > > >> --
> > > >> Chuck Cleland, Ph.D.
> > > >> NDRI, Inc.
> > > >> 71 West 23rd Street, 8th floor
> > > >> New York, NY 10010
> > > >> tel: (212) 845-4495 (Tu, Th)
> > > >> tel: (732) 512-0171 (M, W, F)
> > > >> fax: (917) 438-0894
> > > >>
> > > >
> > >
> > > --
> > > Chuck Cleland, Ph.D.
> > > NDRI, Inc.
> > > 71 West 23rd Street, 8th floor
> > > New York, NY 10010
> > > tel: (212) 845-4495 (Tu, Th)
> > > tel: (732) 512-0171 (M, W, F)
> > > fax: (917) 438-0894
> > >
> >
> > __
> > R-help@stat.math.ethz.ch 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 in lattice densityplot

2006-11-30 Thread Gabor Grothendieck
Me too on Windows XP.

Its probably just a bug or unimplemented feature in the SVG driver.
Write to the maintainer of that package

For a workaround generate fig output and then convert it to svg using whatever
fig editor or converter you have.

(On my windows system I use the free fig2dev converter although it inserted
a DOCTYPE statement into the generated SVG file that IE7 did not recognize
but once I manually deleted that it displayed ok in IE7.)

# after producing file01.fig run
#   fig2dev -L svg file01.fig file01.svg
# or use some other fig to svg converter or editor
xfig(file = "/file01.fig", onefile = TRUE)
library(lattice)
set.seed(1)
DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
   f = sample(c("A","B","C","D","E"),300,replace=TRUE))
densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
 par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2,
 lwd = c(1,1,1,1,2
dev.off()


On 11/30/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> Should it be a problem to print this dashed line plots as svgs?
>
> library(RSvgDevice)
> devSVG(file = "/home/avilella/file01.svg",
>   width = 20, height = 16, bg = "white", fg = "black", onefile=TRUE,
>   xmlHeader=TRUE)
> densityplot(...)
> dev.off()
>
> I am getting all the lines as continuous, not dashed...
>
> On 11/30/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> > Yes  by using the lty suboption of superpose.line.
> > Here is a modification of the prior example to illustrate:
> > We also use lwd as well in this example.
> >
> > set.seed(1)
> > DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
> >f = sample(c("A","B","C","D","E"),300,replace=TRUE))
> > library(lattice)
> > densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
> >  par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2,
> >  lwd = c(1,1,1,1,2
> >
> >
> > On 11/30/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> > > Can I combine colors and line types? For example, would it be possible
> > > to have 5 colors per 2 types of lines (continuous and dashed)?
> > >
> > > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > > > Albert Vilella wrote:
> > > > > Are this legend colors correlated to the plot?
> > > >
> > > >   They are if you rely on the colors in
> > > >
> > > > trellis.par.get("superpose.line")$col
> > > >
> > > >   If you want different colors you might use trellis.par.set() to
> > > > temporarily change the colors:
> > > >
> > > > x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
> > > > f <- rep(c("A","B","C"), each=100)
> > > > df <- data.frame(x,f)
> > > > library(lattice)
> > > >
> > > > oldpar <- trellis.par.get("superpose.line")$col
> > > >
> > > > trellis.par.set(superpose.line = list(col = heat.colors(3)))
> > > >
> > > > densityplot(~ x, groups = f, data = df,
> > > >  plot.points=FALSE,
> > > >  auto.key=TRUE)
> > > >
> > > > trellis.par.set(superpose.line = list(col = oldpar))
> > > >
> > > >   If you don't require points or lines in the key, you also could do
> > > > something like this:
> > > >
> > > > densityplot(~ x, groups = f, data = df,
> > > >  plot.points=FALSE,
> > > >  key = simpleKey(levels(df$f),
> > > >  lines=FALSE,
> > > >  points=FALSE,
> > > >  col=heat.colors(3)),
> > > >  col=heat.colors(3))
> > > >
> > > >   To use your own colors without changing the trellis settings and to
> > > > get lines or points in the key, you probably need at least to use key =
> > > > simpleKey() rather than the auto.key argument, and you may need to look
> > > > into draw.key().  Other people on the list might know simpler approaches
> > > > for using your own colors in this situation.
> > > >
> > > > > If I do a:
> > > > >
> > > > > densityplot(~x, groups=f, plot.points=FALSE,
> > > > > auto.key=TRUE,col=heat.colors(5))
> > > > >
> > > > > I get different colors in the legend than the plot...
> > > > >
> > > > >
> > > > > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > > > >> Albert Vilella wrote:
> > > > >> > Hi,
> > > > >> >
> > > > >> > I have a densityplot like this:
> > > > >> >
> > > > >> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > > > >> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> > > > >> > df=data.frame(x,f)
> > > > >> > library(lattice)
> > > > >> > attach(df)
> > > > >> > densityplot(~x, groups=f)
> > > > >> >
> > > > >> > And I want to add a legend with the colours for the factors. How 
> > > > >> > can
> > > > >> I do that?
> > > > >> > How can I not have the dots of the distribution at the bottom, or 
> > > > >> > at
> > > > >> > least, make them occupy less vertical space?
> > > > >>
> > > > >>   Change the last line to the following:
> > > > >>
> > > > >> densityplot(~x, groups=f, plot.points=FALSE, auto.key

Re: [R] Legend Outside Plot Dimension

2006-01-18 Thread Jacques VESLOT
use "xpd" argument in par(), as follows:

 > ?par
 > par(xpd=T, mar=par()$mar+c(0,0,0,4))
 > plot(1,1)
 > legend(1.5,1,"point",pch=1)


Abd Rahman Kassim a écrit :

>Dear All,
>
>I'm trying to attach a legend outside the plot (Inside plot OK), but failed. 
>Any help is very much appreciated.
>
>Thanks.
>
>
>Abd. Rahman Kassim, PhD
>Forest Management & Ecology Program
>Forestry & Conservation Division
>Forest Research Institute Malaysia
>Kepong 52109 Selangor
>MALAYSIA
>
>*
>
>Checked by TrendMicro Interscan Messaging Security.
>For any enquiries, please contact FRIM IT Department.
>*
>   [[alternative HTML version deleted]]
>
>__
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend Outside Plot Dimension

2006-01-18 Thread Abd Rahman Kassim

Dear Jacques,

Thanks for the promt response.

Abd. Rahman
- Original Message - 
From: "Jacques VESLOT" <[EMAIL PROTECTED]>
To: "Abd Rahman Kassim" <[EMAIL PROTECTED]>
Cc: 
Sent: Wednesday, January 18, 2006 9:15 PM
Subject: Re: [R] Legend Outside Plot Dimension



use "xpd" argument in par(), as follows:

 > ?par
 > par(xpd=T, mar=par()$mar+c(0,0,0,4))
 > plot(1,1)
 > legend(1.5,1,"point",pch=1)


Abd Rahman Kassim a écrit :

>Dear All,
>
>I'm trying to attach a legend outside the plot (Inside plot OK), but 
>failed. Any help is very much appreciated.
>
>Thanks.
>
>
>Abd. Rahman Kassim, PhD
>Forest Management & Ecology Program
>Forestry & Conservation Division
>Forest Research Institute Malaysia
>Kepong 52109 Selangor
>MALAYSIA
>
>*
>
>Checked by TrendMicro Interscan Messaging Security.
>For any enquiries, please contact FRIM IT Department.
>*
> [[alternative HTML version deleted]]
>
>__
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! 
>http://www.R-project.org/posting-guide.html
>
>
>



*

Checked by TrendMicro Interscan Messaging Security.
For any enquiries, please contact FRIM IT Department.
* 


*

Checked by TrendMicro Interscan Messaging Security.
For any enquiries, please contact FRIM IT Department.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend Outside Plot Dimension

2006-01-19 Thread Petr Pikal
Hi

I think you need to use par(xpd=TRUE). Try to search archives as 
similar question was answered few days ago.

HTH
Petr


On 19 Jan 2006 at 12:19, Abd Rahman Kassim wrote:

From:   "Abd Rahman Kassim" <[EMAIL PROTECTED]>
To: 
Date sent:  Thu, 19 Jan 2006 12:19:30 -0800
Subject:        [R] Legend Outside Plot Dimension

> 
> Dear All,
> 
> I'm trying to attach a legend outside the plot (Inside plot OK), but
> failed. Any help is very much appreciated.
> 
> Thanks.
> 
> 
> Abd. Rahman Kassim, PhD
> Forest Management & Ecology Program
> Forestry & Conservation Division
> Forest Research Institute Malaysia
> Kepong 52109 Selangor
> MALAYSIA
> 
> *
> 
> Checked by TrendMicro Interscan Messaging Security.
> For any enquiries, please contact FRIM IT Department.
> *
>  [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend Outside Plot Dimension

2006-01-19 Thread Abd Rahman Kassim

Dear Peter,

Thanks for your promt response. 

Abd. Rahman 
- Original Message - 
From: "Petr Pikal" <[EMAIL PROTECTED]>
To: "Abd Rahman Kassim" <[EMAIL PROTECTED]>; 
Sent: Thursday, January 19, 2006 12:11 AM
Subject: Re: [R] Legend Outside Plot Dimension


> 
> Hi
> 
> I think you need to use par(xpd=TRUE). Try to search archives as 
> similar question was answered few days ago.
> 
> HTH
> Petr
> 
> 
> On 19 Jan 2006 at 12:19, Abd Rahman Kassim wrote:
> 
> From:   "Abd Rahman Kassim" <[EMAIL PROTECTED]>
> To:     
> Date sent:  Thu, 19 Jan 2006 12:19:30 -0800
> Subject:[R] Legend Outside Plot Dimension
> 
>> 
>> Dear All,
>> 
>> I'm trying to attach a legend outside the plot (Inside plot OK), but
>> failed. Any help is very much appreciated.
>> 
>> Thanks.
>> 
>> 
>> Abd. Rahman Kassim, PhD
>> Forest Management & Ecology Program
>> Forestry & Conservation Division
>> Forest Research Institute Malaysia
>> Kepong 52109 Selangor
>> MALAYSIA
>> 
>> *
>> 
>> Checked by TrendMicro Interscan Messaging Security.
>> For any enquiries, please contact FRIM IT Department.
>> *
>>  [[alternative HTML version deleted]]
>> 
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
> 
> Petr Pikal
> [EMAIL PROTECTED]
> 
> 
> 
> *
> Outgoing mail is certified Virus Free.
> Checked by TrendMicro Interscan Messaging Security.
> For any enquiries, please contact FRIM IT Department.
> *

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend in the outer margin

2006-04-10 Thread Prasanna
Dear Rs

I have a 3x3 multiple plot. I would like to have a overall legend in
the outer right margin.
>From the help archive, I found that it can be done by setting
par(xpd=NA). However, I couldn't find the correct values
for x and y co-ordinates for the legend. Please find the code snippet below:

par(mfrow=c(3,3), mar=c(4,4,0.9,0.5), oma=c(1,2,2,4),cex.main=1.1)

  *postscript(*file=epsfile,onefile=FALSE,horizontal=TRUE*)*

/* some plotting */

par(xpd=NA)

legend(legend=c("2h-opt Exact","1-shift Exact","2p-opt Exact"),
lty=c("solid","dashed","dotdash"),lwd=c(2,2,2),col=c("red","green","black"),
bty="n",cex=0.8)

Thanks in advance
Prasanna

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] legend title in effects plot

2006-05-24 Thread Viktor Tron
Could someone tell how I can change/remove the legend title in a  
(multiline) effect plot?
Thanks
V

In general, how is one supposed to find out answers to such questions?
It is virtually impossible to keep track of what graphical parameters are  
passed on
to which low level function and which don't. Every funciton calls legend  
labels a different
name (title, key, legend.lab, etc.).
I tried the help pages of par,plot,effect,legend, without an effect :-)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] legend/plotmath/substitute problem

2006-12-14 Thread Duncan Murdoch
On 12/14/2006 5:05 PM, Philipp Pagel wrote:
>   Dear R Experts,
> 
> I am trying to produce a legend for a series of plots which are
> generated in a loop. The legend is supposed to look like this:
> 
> 2000: gamma=1.8
> 
> where gamma is replaced by the greek letter and both the year and the
> value of gamma are stored in variables.
> 
> Everything works fine as long as I have only one data series:
> 
> year = 2001
> g = 1.9
> plot(1)
> legend('top', legend=substitute(paste(year, ': ', gamma, '=', g), 
> list(year=year, g=g)) )
> 
> 
> My problem starts, when I want to put more than one series of data in
> the plot and accordingly need one legend row per data series:
> 
> year1 = 2001
> year2 = 2005
> g1 = 1.9
> g2 = 1.7
> plot(1)
> legend('top', 
>   legend=c(
>   substitute(paste(year, ': ', gamma, '=', g), list(year=year1, 
> g=g1)),
>   substitute(paste(year, ': ', gamma, '=', g), list(year=year2, 
> g=g2))
>   )
> )
> 
> This obviously does not produce the desired result. Apparently, I am not
> generating a list of expressions, as intended. So I thought, maybe R uses a
> variety of the recycling rule here and tried:

The problem is that legend wants an expression, but substitute() isn't 
returning one, it's returning a call, and c(call1,call2) produces a list 
of two calls, not an expression holding two calls.  So the following 
would work, but there might be something more elegant:

year1 = 2001
year2 = 2005
g1 = 1.9
g2 = 1.7
plot(1)
legend('top',
legend=c(
as.expression(substitute(paste(year, ': ', gamma, '=', g), 
list(year=year1, g=g1))),
as.expression(substitute(paste(year, ': ', gamma, '=', g), 
list(year=year2, g=g2)))
)
)

Duncan Murdoch

> 
> year = c(2001, 2005)
> g = c(1.9, 1.7)
> plot(1)
> legend('top',
> legend=list(
> substitute(paste(year, ': ', gamma, '=', g), list(year=year, g=g)),
> )
> )
> 
> No succes, either...
> 
> I have read and re-read the documentation for legend, expression, substitute
> and plotmath but can't figure it out. Even drinking a cup of tea prepared from
> fine-cut man page printouts didn't lead to satori.
> 
> I'm probably missing something simple. Any hints are highly appreciated.
> 
> Thanks
>   Philipp
>

__
R-help@stat.math.ethz.ch 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/plotmath/substitute problem

2006-12-14 Thread Philipp Pagel
On Thu, Dec 14, 2006 at 06:25:49PM -0500, Duncan Murdoch wrote:
> On 12/14/2006 5:05 PM, Philipp Pagel wrote:
> >My problem starts, when I want to put more than one series of data in
> >the plot and accordingly need one legend row per data series:
> >
> >year1 = 2001
> >year2 = 2005
> >g1 = 1.9
> >g2 = 1.7
> >plot(1)
> >legend('top', 
> > legend=c(
> > substitute(paste(year, ': ', gamma, '=', g), 
> > list(year=year1, g=g1)),
> > substitute(paste(year, ': ', gamma, '=', g), 
> > list(year=year2, g=g2))
> > )
> >)
> >
> >This obviously does not produce the desired result. Apparently, I am not
> >generating a list of expressions, as intended. So I thought, maybe R uses a
> >variety of the recycling rule here and tried:
> 
> The problem is that legend wants an expression, but substitute() isn't 
> returning one, it's returning a call, and c(call1,call2) produces a list 
> of two calls, not an expression holding two calls.  So the following 
> would work, but there might be something more elegant:

Thanks a lot! Learned something, again.

cu
Philipp

-- 
Dr. Philipp PagelTel.  +49-8161-71 2131
Dept. of Genome Oriented Bioinformatics  Fax.  +49-8161-71 2186
Technical University of Munich
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@stat.math.ethz.ch 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 in lattice densityplot

2007-02-14 Thread Albert Vilella
How can I place the legend to the left or right of the densityplot? By
default, it goes at the top, and as it is a rather long list, the
density plot only uses half the space of the whole graphic...

On 11/30/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> Me too on Windows XP.
>
> Its probably just a bug or unimplemented feature in the SVG driver.
> Write to the maintainer of that package
>
> For a workaround generate fig output and then convert it to svg using whatever
> fig editor or converter you have.
>
> (On my windows system I use the free fig2dev converter although it inserted
> a DOCTYPE statement into the generated SVG file that IE7 did not recognize
> but once I manually deleted that it displayed ok in IE7.)
>
> # after producing file01.fig run
> #   fig2dev -L svg file01.fig file01.svg
> # or use some other fig to svg converter or editor
> xfig(file = "/file01.fig", onefile = TRUE)
> library(lattice)
> set.seed(1)
> DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
>f = sample(c("A","B","C","D","E"),300,replace=TRUE))
> densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
>  par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2,
>  lwd = c(1,1,1,1,2
> dev.off()
>
>
> On 11/30/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> > Should it be a problem to print this dashed line plots as svgs?
> >
> > library(RSvgDevice)
> > devSVG(file = "/home/avilella/file01.svg",
> >   width = 20, height = 16, bg = "white", fg = "black", onefile=TRUE,
> >   xmlHeader=TRUE)
> > densityplot(...)
> > dev.off()
> >
> > I am getting all the lines as continuous, not dashed...
> >
> > On 11/30/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> > > Yes  by using the lty suboption of superpose.line.
> > > Here is a modification of the prior example to illustrate:
> > > We also use lwd as well in this example.
> > >
> > > set.seed(1)
> > > DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
> > >f = sample(c("A","B","C","D","E"),300,replace=TRUE))
> > > library(lattice)
> > > densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
> > >  par.settings = list(superpose.line = list(col = c(1,1,2,2), lty = 1:2,
> > >  lwd = c(1,1,1,1,2
> > >
> > >
> > > On 11/30/06, Albert Vilella <[EMAIL PROTECTED]> wrote:
> > > > Can I combine colors and line types? For example, would it be possible
> > > > to have 5 colors per 2 types of lines (continuous and dashed)?
> > > >
> > > > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > > > > Albert Vilella wrote:
> > > > > > Are this legend colors correlated to the plot?
> > > > >
> > > > >   They are if you rely on the colors in
> > > > >
> > > > > trellis.par.get("superpose.line")$col
> > > > >
> > > > >   If you want different colors you might use trellis.par.set() to
> > > > > temporarily change the colors:
> > > > >
> > > > > x <- c(rnorm(100,-2,1),rnorm(100,0,1),rnorm(100,2,1))
> > > > > f <- rep(c("A","B","C"), each=100)
> > > > > df <- data.frame(x,f)
> > > > > library(lattice)
> > > > >
> > > > > oldpar <- trellis.par.get("superpose.line")$col
> > > > >
> > > > > trellis.par.set(superpose.line = list(col = heat.colors(3)))
> > > > >
> > > > > densityplot(~ x, groups = f, data = df,
> > > > >  plot.points=FALSE,
> > > > >  auto.key=TRUE)
> > > > >
> > > > > trellis.par.set(superpose.line = list(col = oldpar))
> > > > >
> > > > >   If you don't require points or lines in the key, you also could do
> > > > > something like this:
> > > > >
> > > > > densityplot(~ x, groups = f, data = df,
> > > > >  plot.points=FALSE,
> > > > >  key = simpleKey(levels(df$f),
> > > > >  lines=FALSE,
> > > > >  points=FALSE,
> > > > >  col=heat.colors(3)),
> > > > >  col=heat.colors(3))
> > > > >
> > > > >   To use your own colors without changing the trellis settings and to
> > > > > get lines or points in the key, you probably need at least to use key 
> > > > > =
> > > > > simpleKey() rather than the auto.key argument, and you may need to 
> > > > > look
> > > > > into draw.key().  Other people on the list might know simpler 
> > > > > approaches
> > > > > for using your own colors in this situation.
> > > > >
> > > > > > If I do a:
> > > > > >
> > > > > > densityplot(~x, groups=f, plot.points=FALSE,
> > > > > > auto.key=TRUE,col=heat.colors(5))
> > > > > >
> > > > > > I get different colors in the legend than the plot...
> > > > > >
> > > > > >
> > > > > > On 11/29/06, Chuck Cleland <[EMAIL PROTECTED]> wrote:
> > > > > >> Albert Vilella wrote:
> > > > > >> > Hi,
> > > > > >> >
> > > > > >> > I have a densityplot like this:
> > > > > >> >
> > > > > >> > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > > > > >> > f = sample(c("A","B","C","D","E"),300,replace=TRUE)
> > > > > >> > df=data.frame(x,f

Re: [R] legend under plot region?

2004-07-30 Thread partha_bagchi
Have a look at 
?par

You need to have par(xpd = TRUE) and then use par("usr") to get the 
coordinates for the edges of the plot. Also make sure you have enough 
space around the plot to put the legend. For that, have a look at par(oma) 
or par(mar) etc.

HTH.
Partha






Jean Eid <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
07/30/2004 02:21 PM

 
To: [EMAIL PROTECTED]
cc: 
Subject:    [R] legend under plot region?


I am trying to put legends underneath the plot (in the outer margins). Is
there an easy way to do this. I have been tinkering with split..screen but
I could not make it work.

Thank in advance

Jean

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Legend with different sized symbols

2004-08-05 Thread J. Pedro Granadeiro
Dear list,

I wonder if it is possible to produce a legend with symbols of different sizes 
using a single legend command. I managed to do so more or less like in this 
crude example, but there is probably a smarter and more practical way:

set.seed(0)
plot(rnorm(100), rnorm(100), cex=rep(1:5,each=20))
x<-legend(-2,2.8, legend=1:5, pch="  ",y.intersp=2, bty="n")
points(x$text$x-.2,x$text$y, cex=1:5)

I tried with playing with cex inside the legend command, but this gave me 
funny results, since it manipulates the overall size of symbols plus text. I 
was looking for something like "pt.cex", but this probably it does not 
exist...

Thanks

Jose Pedro Granadeiro

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend/Substitute/Plotmath problem

2004-10-25 Thread Martin Maechler
> "Johannes" == Johannes Graumann <[EMAIL PROTECTED]>
> on Sat, 23 Oct 2004 11:04:25 -0700 writes:
> "Johannes" == Johannes Graumann <[EMAIL PROTECTED]>
> on Sat, 23 Oct 2004 11:04:25 -0700 writes:

Johannes> Hello,

Johannes> I seem unable to construct a legend which contains
Johannes> a substitution as well as math symbols. I'm trying
Johannes> to do the following:

>> strain2 <- "YJG48"

>> legend.txt <- c(
>>  substitute(
>>  strain *
>>  %==% *
>>  "YJG45, rpn10" *
>>  %Delta%,
>>  list(strain=strain2)
>>  ),
>>  "Verhulst/Logistic",
>>  "Malthus"
>> )


Johannes> .

Do try to break down a problem into simple things --
particularly when you have problems!

This substitute() call is simply invalid:

  > ss <- substitute( strain * %==% * "YJG45, rpn10" * %Delta%, list(strain=strain2) )
  Error: syntax error

and the 'syntax error' should give you a clue:  
The first argument of substitute must be a syntactically correct
R expression.

Now you try more and more simple things till you 'see it' :

Why should I expect  'A * %==% B'  to be valid syntax?
Both '*' and '%==%' are (diadic) operators: You can't juxtapose
them, as well as you can't write  'A * = B'.
Then, '%Delta%' (like any other '%foo%' !!) is a diadic operator
too and hence can't be juxtaposed to '*'. But I'm pretty sure
you rather mean (greek) 'Delta'.

Hence:
 ss <- substitute( strain %==% "YJG45, rpn10" * Delta, list(strain=strain2) )

---

Once you have the expression you can go further;
still step by step :

  > c(ss, "Verhulst")
  [[1]]
  "YJG48" %==% "YJG45, rpn10" * Delta

  [[2]]
  [1] "Verhulst"

Hmm, a list; that won't work.
You do need to pass either a "character" vector or an
expression, i.e., an expression of length 3 in our case.
We must build the expression somewhat manually:

  > e <- expression(1, "Verhulst", "Malthus")# '1' is a place holder
expression(1, "Verhulst", "Malthus")
  > e[[1]] <- ss  ## that's the trick!

  > str(e)
expression("YJG48" %==% "YJG45, rpn10" * Delta, "Verhulst", "Malthus")

  > plot(1); legend(1,1, leg = e)

---

Maybe something to be added as an example to help(legend) or rather
to help(expression) ?

HTH,
Martin Maechler, ETH Zurich

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend/Substitute/Plotmath problem

2004-10-25 Thread Uwe Ligges
Martin Maechler wrote:
"Johannes" == Johannes Graumann <[EMAIL PROTECTED]>
   on Sat, 23 Oct 2004 11:04:25 -0700 writes:
"Johannes" == Johannes Graumann <[EMAIL PROTECTED]>
   on Sat, 23 Oct 2004 11:04:25 -0700 writes:

Johannes> Hello,
Johannes> I seem unable to construct a legend which contains
Johannes> a substitution as well as math symbols. I'm trying
Johannes> to do the following:
>> strain2 <- "YJG48"
>> legend.txt <- c(
>>substitute(
>>strain *
>>%==% *
>>"YJG45, rpn10" *
>>%Delta%,
>>list(strain=strain2)
>>),
>>"Verhulst/Logistic",
>>"Malthus"
>> )
Johannes> .
Do try to break down a problem into simple things --
particularly when you have problems!
This substitute() call is simply invalid:
  > ss <- substitute( strain * %==% * "YJG45, rpn10" * %Delta%, list(strain=strain2) )
  Error: syntax error
and the 'syntax error' should give you a clue:  
The first argument of substitute must be a syntactically correct
R expression.

Now you try more and more simple things till you 'see it' :
Why should I expect  'A * %==% B'  to be valid syntax?
Both '*' and '%==%' are (diadic) operators: You can't juxtapose
them, as well as you can't write  'A * = B'.
Then, '%Delta%' (like any other '%foo%' !!) is a diadic operator
too and hence can't be juxtaposed to '*'. But I'm pretty sure
you rather mean (greek) 'Delta'.
Hence:
 ss <- substitute( strain %==% "YJG45, rpn10" * Delta, list(strain=strain2) )
---
Once you have the expression you can go further;
still step by step :
  > c(ss, "Verhulst")
  [[1]]
  "YJG48" %==% "YJG45, rpn10" * Delta
  [[2]]
  [1] "Verhulst"
Hmm, a list; that won't work.
You do need to pass either a "character" vector or an
expression, i.e., an expression of length 3 in our case.
We must build the expression somewhat manually:
  > e <- expression(1, "Verhulst", "Malthus")# '1' is a place holder
expression(1, "Verhulst", "Malthus")
  > e[[1]] <- ss  ## that's the trick!
  > str(e)
expression("YJG48" %==% "YJG45, rpn10" * Delta, "Verhulst", "Malthus")
  > plot(1); legend(1,1, leg = e)
---
Maybe something to be added as an example to help(legend) or rather
to help(expression) ?
Martin, a small example is given in the Help Desk in R News 2 (3). Maybe 
you want to include it ...

Uwe

HTH,
Martin Maechler, ETH Zurich
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend/Substitute/Plotmath problem

2004-10-25 Thread Johannes Graumann
Thank you so much ... works now ... sooo much to learn ...

Joh

On Mon, 25 Oct 2004 09:56:35 +0200
Martin Maechler <[EMAIL PROTECTED]> wrote:

> > "Johannes" == Johannes Graumann <[EMAIL PROTECTED]>
> > on Sat, 23 Oct 2004 11:04:25 -0700 writes:
> > "Johannes" == Johannes Graumann <[EMAIL PROTECTED]>
> > on Sat, 23 Oct 2004 11:04:25 -0700 writes:
> 
> Johannes> Hello,
> 
> Johannes> I seem unable to construct a legend which contains
> Johannes> a substitution as well as math symbols. I'm trying
> Johannes> to do the following:
> 
> >> strain2 <- "YJG48"
> 
> >> legend.txt <- c(
> >>substitute(
> >>strain *
> >>%==% *
> >>"YJG45, rpn10" *
> >>%Delta%,
> >>list(strain=strain2)
> >>),
> >>"Verhulst/Logistic",
> >>"Malthus"
> >> )
> 
> 
> Johannes> .
> 
> Do try to break down a problem into simple things --
> particularly when you have problems!
> 
> This substitute() call is simply invalid:
> 
>   > ss <- substitute( strain * %==% * "YJG45, rpn10" * %Delta%,
>   > list(strain=strain2) )
>   Error: syntax error
> 
> and the 'syntax error' should give you a clue:  
> The first argument of substitute must be a syntactically correct
> R expression.
> 
> Now you try more and more simple things till you 'see it' :
> 
> Why should I expect  'A * %==% B'  to be valid syntax?
> Both '*' and '%==%' are (diadic) operators: You can't juxtapose
> them, as well as you can't write  'A * = B'.
> Then, '%Delta%' (like any other '%foo%' !!) is a diadic operator
> too and hence can't be juxtaposed to '*'. But I'm pretty sure
> you rather mean (greek) 'Delta'.
> 
> Hence:
>  ss <- substitute( strain %==% "YJG45, rpn10" * Delta,
>  list(strain=strain2) )
> 
> ---
> 
> Once you have the expression you can go further;
> still step by step :
> 
>   > c(ss, "Verhulst")
>   [[1]]
>   "YJG48" %==% "YJG45, rpn10" * Delta
> 
>   [[2]]
>   [1] "Verhulst"
> 
> Hmm, a list; that won't work.
> You do need to pass either a "character" vector or an
> expression, i.e., an expression of length 3 in our case.
> We must build the expression somewhat manually:
> 
>   > e <- expression(1, "Verhulst", "Malthus")# '1' is a place holder
> expression(1, "Verhulst", "Malthus")
>   > e[[1]] <- ss  ## that's the trick!
> 
>   > str(e)
> expression("YJG48" %==% "YJG45, rpn10" * Delta, "Verhulst",
> "Malthus")
> 
>   > plot(1); legend(1,1, leg = e)
> 
> ---
> 
> Maybe something to be added as an example to help(legend) or rather
> to help(expression) ?
> 
> HTH,
> Martin Maechler, ETH Zurich
> 
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-03 Thread Marc Schwartz
On Wed, 2004-11-03 at 09:55, Dan Bolser wrote:
> This has been asked before, but all the answers are hidiously complex.
> 
> The
> 
> legend.text=TRUE 
> 
> option of barplot is almost exactly what I need, except I need a
> 
> legend.placement='tl'
> 
> (top left) option. This option would be in contrast to the default
> placement which we could call 'tr' (top right).
> 
> Anyone know how to edit the barplot code to make this change? Could
> someone like me work out how to do this?
> 
> Cheers,
> Dan.

Dan,

Do not edit the barplot() code. Use the legend() function instead, which
enables you to specify the x,y coordinates of the upper left hand corner
of the legend box. See ?legend

A fair number of the questions that you have had regarding graphics are
covered in Chapter 12 "Graphical Procedures" in "An Introduction to R":

http://cran.r-project.org/doc/manuals/R-intro.pdf

which is included with the R installation.

Another online resource for some graphics assistance would be R News
Volume 3 Number 2 for October 2003, which has an article on R's base
graphics in the R Help Desk section:

http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf

Notwithstanding all of that, searching the r-help archives is yet
another terrific online (and free) resource that you _should_ avail
yourself of.

HTH,

Marc Schwartz

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-03 Thread Gabor Grothendieck
Dan Bolser  mrc-dunn.cam.ac.uk> writes:

: 
: This has been asked before, but all the answers are hidiously complex.
: 
: The
: 
: legend.text=TRUE 
: 
: option of barplot is almost exactly what I need, except I need a
: 
: legend.placement='tl'
: 
: (top left) option. This option would be in contrast to the default
: placement which we could call 'tr' (top right).
: 
: Anyone know how to edit the barplot code to make this change? Could
: someone like me work out how to do this?
: 


In package gplots (in bundle gregmisc in R 2.0.0) there is smartlegend.

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-03 Thread Gabor Grothendieck
Dan Bolser  mrc-dunn.cam.ac.uk> writes:

: 
: This has been asked before, but all the answers are hidiously complex.
: 
: The
: 
: legend.text=TRUE 
: 
: option of barplot is almost exactly what I need, except I need a
: 
: legend.placement='tl'
: 
: (top left) option. This option would be in contrast to the default
: placement which we could call 'tr' (top right).
: 
: Anyone know how to edit the barplot code to make this change? Could
: someone like me work out how to do this?
: 
: Cheers,
: Dan.


Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-04 Thread Dan Bolser
On Wed, 3 Nov 2004, Marc Schwartz wrote:

>On Wed, 2004-11-03 at 09:55, Dan Bolser wrote:
>> This has been asked before, but all the answers are hidiously complex.
>> 
>> The
>> 
>> legend.text=TRUE 
>> 
>> option of barplot is almost exactly what I need, except I need a
>> 
>> legend.placement='tl'
>> 
>> (top left) option. This option would be in contrast to the default
>> placement which we could call 'tr' (top right).
>> 
>> Anyone know how to edit the barplot code to make this change? Could
>> someone like me work out how to do this?
>> 
>> Cheers,
>> Dan.
>
>Dan,
>
>Do not edit the barplot() code. Use the legend() function instead, which
>enables you to specify the x,y coordinates of the upper left hand corner
>of the legend box. See ?legend

Thing is I need to pass legend the correct groups and correct plotting
colors and correct XY position relative to my data. All these things are
already known by the barplot function, and used to draw a beautiful
legend.

The fact that this legend can only appear in the upper right hand corner
is surly a bug worthy of changing the code for?


>A fair number of the questions that you have had regarding graphics are
>covered in Chapter 12 "Graphical Procedures" in "An Introduction to R":
>
>http://cran.r-project.org/doc/manuals/R-intro.pdf
>
>which is included with the R installation.
>
>Another online resource for some graphics assistance would be R News
>Volume 3 Number 2 for October 2003, which has an article on R's base
>graphics in the R Help Desk section:
>
>http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf

Thanks for the links

>Notwithstanding all of that, searching the r-help archives is yet
>another terrific online (and free) resource that you _should_ avail
>yourself of.


Quoting me... "This has been asked before, but all the answers are
hidiously complex."



>HTH,
>
>Marc Schwartz
>
>

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-04 Thread Dan Bolser
On Wed, 3 Nov 2004, Gabor Grothendieck wrote:

>Dan Bolser  mrc-dunn.cam.ac.uk> writes:
>
>: 
>: This has been asked before, but all the answers are hidiously complex.
>: 
>: The
>: 
>: legend.text=TRUE 
>: 
>: option of barplot is almost exactly what I need, except I need a
>: 
>: legend.placement='tl'
>: 
>: (top left) option. This option would be in contrast to the default
>: placement which we could call 'tr' (top right).
>: 
>: Anyone know how to edit the barplot code to make this change? Could
>: someone like me work out how to do this?
>: 
>: Cheers,
>: Dan.
>
>
>Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).


This works great, but like the (smart)legend function, fill=true appears
to be giving me only black boxes.

Here is what I add..

smartlegend(x="left",y="top",
c("PDB","MSD"),
fill=TRUE,
col=c("red","blue")
   )

The result is two black boxes! I tried swapping the order of the color and
fill options, but to the same effect.

I got round the problem by using...

smartlegend(x="left",y="top",
c("PDB","MSD"),
col=c("red","blue"),
lwd=5
)

Not quite the same, but good enough.


One other thing (while I am generally complaining), the legend dosn't
scale correctly as I change the image size with the mouse. All the other
aspects of the barplot scale correctly. If I redraw the legend after
changing the size it is scaled correctly, suggesting that this problem
isn't fundamental, but is a bug in the implementation of legend.



>
>__
>[EMAIL PROTECTED] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-04 Thread Henric Nilsson
At 13:24 2004-11-04 +, Dan Bolser wrote:
>Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).
This works great, but like the (smart)legend function, fill=true appears
to be giving me only black boxes.
Here is what I add..
smartlegend(x="left",y="top",
c("PDB","MSD"),
fill=TRUE,
col=c("red","blue")
   )
For coloured boxes, use
smartlegend(x="left",
   y="top",
   c("PDB","MSD"),
 fill=c("red","blue"))
HTH,
Henric
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-04 Thread F Z
You can use locator()  nested within legend()
i.e.
plot(YourVariable)
legend(locator(1),legend="Your Legend")
Once you call this command it will display "Your Legend" in the place where 
you left clicked your mouse.  Beware that, as described in the documentation 
"...'locator' is only supported on screen devices such as 'X11','windows' 
and 'quartz'.  On other devices the call will do nothing"

Altrenativelly you can pass the exact coordinates of the position where you 
want the legend, instead of using locator
i.e.

plot(YourVariable)
x<-list(x=-91.76781, y=46.87375)
legend(x,legend="Your Legend")
I hope that this helps
Francisco
From: Gabor Grothendieck <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: [R] Legend placement in barplot?
Date: Wed, 3 Nov 2004 18:48:48 + (UTC)
Dan Bolser  mrc-dunn.cam.ac.uk> writes:
:
: This has been asked before, but all the answers are hidiously complex.
:
: The
:
: legend.text=TRUE
:
: option of barplot is almost exactly what I need, except I need a
:
: legend.placement='tl'
:
: (top left) option. This option would be in contrast to the default
: placement which we could call 'tr' (top right).
:
: Anyone know how to edit the barplot code to make this change? Could
: someone like me work out how to do this?
:
: Cheers,
: Dan.
Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Legend placement in barplot?

2004-11-04 Thread Dan Bolser
On Fri, 5 Nov 2004, F Z wrote:

>You can use locator()  nested within legend()
>i.e.
>
>plot(YourVariable)
>legend(locator(1),legend="Your Legend")
>
>Once you call this command it will display "Your Legend" in the place where 
>you left clicked your mouse.  Beware that, as described in the documentation 
>"...'locator' is only supported on screen devices such as 'X11','windows' 
>and 'quartz'.  On other devices the call will do nothing"
>
>
>Altrenativelly you can pass the exact coordinates of the position where you 
>want the legend, instead of using locator
>i.e.
>
>plot(YourVariable)
>x<-list(x=-91.76781, y=46.87375)
>legend(x,legend="Your Legend")
>
>I hope that this helps
>
>Francisco

Thanks very much for the tips. Basically I want a very flexible solution
that lets me punch the numbers in - take a look at the result and then
immediatly dump a .ps / .eps / .png format of what I saw. The result
should be very quickly 'publication quality' (whatever that is). 

The problem with locator is that I don't know how to make it work with
postscript, and I don't want to find out. I don't want to have to probe my
figure for the coordinates every time I change the data in my figure. I am
happy saying something like 'oh, top left is bad, lets use top right' -
done.

smartlegend is almost there, I just think barplot should support exactly
the same functionality as smartlegend. This would save me the hassle of
creating a new legend every time my data changes, matching up colors and
names.

I am sure their is a way to code this, but I don't want to write code - at
least not code that I have to look at when what I want to see is my data. 


>
>>From: Gabor Grothendieck <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED]
>>Subject: Re: [R] Legend placement in barplot?
>>Date: Wed, 3 Nov 2004 18:48:48 + (UTC)
>>
>>Dan Bolser  mrc-dunn.cam.ac.uk> writes:
>>
>>:
>>: This has been asked before, but all the answers are hidiously complex.
>>:
>>: The
>>:
>>: legend.text=TRUE
>>:
>>: option of barplot is almost exactly what I need, except I need a
>>:
>>: legend.placement='tl'
>>:
>>: (top left) option. This option would be in contrast to the default
>>: placement which we could call 'tr' (top right).
>>:
>>: Anyone know how to edit the barplot code to make this change? Could
>>: someone like me work out how to do this?
>>:
>>: Cheers,
>>: Dan.
>>
>>
>>Check out gplots::smartlegend (in the R 2.0.0 gregmisc bundle).
>>
>>__
>>[EMAIL PROTECTED] mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! 
>>http://www.R-project.org/posting-guide.html
>
>__
>[EMAIL PROTECTED] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


  1   2   >