Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Legend not displaying color

Tags:

plot

r

legend

I have drawn a plot in R.

plot(NA,xlim=c(0,1),ylim=c(0,1), xlab=expression(delta),ylab="K", xaxs="i",yaxs="i",main = "Zones of extreme equality and inequality in BO1") # Empty plot
cols <- c("red","black")
legend("topright",legend=c("Gini < 0.05","Gini > 0.6"), density=c(NA,NA), angle=c(NA,NA), col=cols)

The box in the legend is not getting coloured. What is wrong here ?

like image 537
Ashni Goyal Avatar asked Nov 30 '22 21:11

Ashni Goyal


2 Answers

Try using pch:

legend("topright",
       legend=c("Gini < 0.05","Gini > 0.6"), 
       pch=15,
       col=cols)
like image 159
Jilber Urbina Avatar answered Dec 04 '22 00:12

Jilber Urbina


You can also just put the colors in fill:

legend("topright",legend=c("Gini < 0.05","Gini > 0.6"), fill=cols)
like image 32
davep Avatar answered Dec 04 '22 00:12

davep