Abhishek Gupta
Abhishek Gupta

Reputation: 77

r: barplot - legends issue

Product Sales per month**strong text**

How can I get rid of the boxes in legends and get colored lines instead? Also, how do I place them at a corner? This is the command I am using:

barplot(as.matrix(month_wise_data), main="Product sold per month",
    xlab="Products", col=brewer.pal(nrow(month_wise_data), "Paired"),legend = as.character(month_wise_data[,"MONTH"]), beside=TRUE,
    args.legend=list(x=100,y=10,bty = "n",pt.lwd=0.1, ncol = 3, cex=0.5,pch=1))

Upvotes: 0

Views: 465

Answers (1)

Pierre Lapointe
Pierre Lapointe

Reputation: 16277

You have to add a separate legend call like so:

barplot(VADeaths,beside =TRUE,col=1:5,ylim=c(0,100))
legend("topleft",legend=rownames(VADeaths),col=1:5,lty=1)

enter image description here

Upvotes: 4

Related Questions