neversaint
neversaint

Reputation: 64044

Combining Line and Barplot Legend in R

Is ther a way to do it?

My current code:

barplot(to_plot_bar,col=cm.colors(6,alpha=1),width=0.75,space=0.2,names.arg=x)
lines(dat_dens,lty=1,col="black");
legend("topright",ltext,bty="n",fill=cm.colors(6),
lty = c(0,0,0,0,0,0,1), lwd = c(0,0,0,0,0,1));

Generate such legend.

enter image description here

Upvotes: 3

Views: 3303

Answers (1)

vinux
vinux

Reputation: 965

Try this

ltext1 <- c(ltext,"emp") # this is not necessary if you already added 
legend("topright",ltext1,bty="n",col=c(cm.colors(6),"black"),pch=c(rep(15,6),-1),
       lty = c(0,0,0,0,0,0,1));

Upvotes: 6

Related Questions