How to color the caption according to the graph in the R

Hello guys I have a chart on R and would like to make the caption equal to the chart. below is the command used and the graphic image.

control = c(100,100,100,100,100)
dez = c(100,90,0,0,0)
cinco = c(100,100,100,50,0)
dois = c(100,100,100,100,0)
hours = c(0,24,48,60,72)

plot(control~hours,ylim = c(0,120),xlim = c(0,80),type = 'l',col='black',pch = 1,lwd = 2)

points(control~hours,t = 'p',pch = 16,col='green')
points(dez~hours,type = 'l',pch = 16,col='black',lwd = 2)
points(dez~hours,t = 'p',pch = 16,col='blue')
points(cinco~hours,t = 'l',col='black',lwd = 2)
points(cinco~hours,t = 'p',pch = 16,col='red')
points(dois~hours,t = 'l',col='black',lwd =2)
points(dois~hours,t = 'p',pch = 16,col='orange')

legend('bottomleft',legend = c('Control','10 mg/mL','5 mg/mL','2,5 mg/mL'),col = "black",lty = 1,lwd=2 ,pch=16)

And with that generated this graph.

Graphics

What I would like to do is paint the legend balls according to the color that is on the chart. Thanks.

 4
Author: Comunidade, 2017-03-24

1 answers

You can put one caption on top of the other with transparent background:

legend('bottomleft',
       legend = c('Control','10 mg/mL','5 mg/mL','2,5 mg/mL'),
       col = c("black"), lty = 1, lwd=2, pch = NA)

legend('bottomleft',
       legend = c('Control','10 mg/mL','5 mg/mL','2,5 mg/mL'),
       col = c("green", "blue", "red", "orange"), lty = 0, lwd=2, pch = 16, 
       bg='transparent')

insert the description of the image here

 3
Author: Carlos Cinelli, 2017-03-25 18:51:20