Manish
Manish

Reputation: 3521

How to plot a legend with a border in R?

I'm using R to plot charts and their legends but I found some issues while drawing a legend with a border.

plot.new()
legend(x=0, y=.15, c("Some Text"), cex=1, pt.cex =1.4, col=c("green"), 
       bty="n", fill="green", pch=c(15, 15, 15, 17), border="black")

enter image description here

The border does not completely surround the green box. How can I fix this?

Upvotes: 1

Views: 914

Answers (1)

gung - Reinstate Monica
gung - Reinstate Monica

Reputation: 11893

There is a conflict within the legend() call between fill="green", and pch=c(15, 15, 15, 17). If I drop the latter, I get what I think you are looking for:

plot.new()
legend(x=0,y=.15, c("Some Text"), cex=1,pt.cex =1.4,col=c("green"), 
       bty="n",fill="green", border="black")

enter image description here

Upvotes: 1

Related Questions