Here's one approach.  I changed to the graph a bit to include the extremes
of all of the curves, which may or may not be what you want.

Jean

a <- 0.05
b <- 1
kr <- c(70, 60, 50)
K <- kr/a
colz <- c("blue","green","red")

# determine the limits of the graph
maxatx <- kr*b/(2*a)
maxaty <- kr*maxatx*(b-a*maxatx/kr)/1000
xlimits <- c(-50, 1500)
yatxl1 <- kr*xlimits[1]*(b-a*xlimits[1]/kr)/1000
yatxl2 <- kr*xlimits[2]*(b-a*xlimits[2]/kr)/1000

plot(1, 1, type="n", xlim=xlimits, ylim=range(maxaty, yatxl1, yatxl2),
las=1, xlab="Nombre d'individus", ylab="Creixement  (* 1,000)")
for(i in seq(kr)) {
curve(kr[i]*x*(b-a*x/kr[i])/1000, col=colz[i], add=TRUE)
 points(K[i], 0, pch=16, col=colz[i])
text(K[i], -1, paste0("\n\nK", i, " =\n", K[i]), col=colz[i])
 }
title("Relació del creixement en funció del nombre d'individus")
abline(h=0, v=0, lty=3)
legend("topright", paste0("Kr", seq(kr), " = ", kr), lty=1, col=colz,
bty="n")



On Fri, Dec 27, 2013 at 10:34 AM, <alejandro.th.na@gmail.com> wrote:

> Hi, I don’t really have a problem, but I’m trying to improve my R
> abilities and I think I might use some help.
>
>
> I’ve done this graph:
>
>
> a<-.05; b<- 1; kr1<-70;kr2<-60;kr3<-50
> K1<- kr1/a; K2<- kr2/a; K3<- kr3/a
> curve(kr1*x*(b-a*x/kr1),col="blue",from=-50,to=1500,xlab="Nombre
> d'individus",ylab="Creixement");
> curve(kr2*x*(b-a*x/kr2),col="green",add=T);
> curve(kr3*x*(b-a*x/kr3),col="red",add=T);
> title("Relació del creixement en funció del nombre d'individus")
> abline(h=0,v=0,lty=3)
> legend("topright",legend =c("Kr1=70", "Kr2=60", "Kr3=50"),pch = 22,
> col=NA, pt.bg=c("blue","green","red"))
> points(K1,0, col="blue",pch=20); text(K1,-1000,"K1=1400",col="blue")
> points(K2,0, col="green",pch=20); text(K2,-1000,"K2=1200",col="green")
> points(K3,0, col="red",pch=20); text(K3,-1000,"K3=1000",col="red")
>
>
> And it has everything I need it to, but I’m sure I could have obtained the
> same image using a color vector, a kr vector and a K vector that gathers
> all my values for those variables. I know nothing about loops and I think
> they’re what’s needed here.
>
>
> Could you help me optimize this?
>
>
> Thank you very much.
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

	[[alternative HTML version deleted]]

