简体   繁体   中英

Legend not displaying color

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 ?

Try using pch :

legend("topright",
       legend=c("Gini < 0.05","Gini > 0.6"), 
       pch=15,
       col=cols)

你也可以把颜色填入:

legend("topright",legend=c("Gini < 0.05","Gini > 0.6"), fill=cols)

也许你这样试试:

legend("topright",legend=c("Gini < 0.05","Gini > 0.6"), pch=15, col=cols)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM