pb with legend()

hi
with this code i really dont understand why the lines for the legend do not appear…
i tried to understand but can't find any reason and means to fix that…

setwd("/Users/me
![kokrdssqsdsdddsdsqq|480x480](upload://khRxKwyoZuAfIdllLmOKdq9skms.png)
/Dropbox/_aj_liens")
n=10
plage <- seq(0.1,10,len=n)
#s_scale=seq(0.5,10,len=n)
#curve(dgamma(x,shape=a_shape,scale=s_scale),
 #     xlab="a=1",ylab="",
  #    add=TRUE)
png("kokrdssqsdsdddsdsqq.png")
par(mfrow=c(2,2))
# ------ a=1 --------
plot.new() 
a_shape =1
for (s_scale in plage){
  curve(dgamma(x,shape=a_shape,scale=s_scale),
        xlab="a=1",ylab="",
        xlim=c(0,1),
        col=s_scale,
        ylim=c(0,1),
        axes=TRUE,
        add=TRUE)
}
axis(1) # Ajoute l'axe des x en bas
axis(2) # Ajoute l'axe des y à gauche
  legend("topright",
        legend=c(1:n),
        col=plage
       )
  # ------ a=2 --------
  plot.new() 
  a_shape =2
  for (s_scale in plage){
    curve(dgamma(x,shape=a_shape,scale=s_scale),
          xlab="a=2",ylab="",
          col=s_scale,
          ylim=c(0,1),
          add=TRUE)
  }
  legend("topright",
         legend=c(1:n),
         col=plage
  )    
dev.off()

link to the picture generated :slight_smile: https://www.dropbox.com/s/dfugihk1io3zujb/kokrdssqsdsdddsdsqq.png?dl=0

The answer is in the details of the arguments:

?legend
lty, lwd the line types and widths for lines appearing in the legend. One of these two must be specified for line drawing.

So you just need to specify it:

legend("topright",
       lwd=1,
       legend=c(1:n),
       col=plage
)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.