0

I have a scatterplot I need to add a legend to. It looks like the code is correct but it isn't getting added. Any thoughts?

Dancenew<-subset(Dance, Type=="Lindy" | Type== "Blues" | Type=="Blues")
box.labels<-c("Lindy","Blues","Blues") 
plot(Type~Count, pch=c(19,5,12), col=c("red","blue","green"), ylab="Dance Counts", 
data=ausportnew, xlab="Dance Types", name=box.labels, main="Dancing for a Healthier You")
legend(Dancenew,c("Lindy","Blues","Contra"),pch=c(19,5,12),col=c("red","blue","green"))
Vixxen81
  • 33
  • 1
  • 7
  • Hi! Could you please provide a reproducible example? We do not have `Dance` object. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Marcin Nov 26 '15 at 22:01

1 Answers1

0

Difficult to answer with lack of information, but you could try something like this

set.seed(35)   
Dance=data.frame(Count=runif(40,25,39),Type=rep(c("Lindy","Blues","Blues2","Contra"),each=10),stringsAsFactors= FALSE)
Dancenew<-subset(Dance, Type=="Lindy" | Type== "Blues" | Type=="Contra")
box.labels<-(unique(Dancenew$Type))
Dancenew$Type=factor(Dancenew$Type)
plot(Type~Count, pch=c(19,5,10), col=c("red","blue","green"), ylab="Dance Types", data=Dancenew, xlab="Dance Counts",  main="Dancing for a Healthier You")
legend("top",legend=box.labels,pch=c(19,5,10),col=c("red","blue","green"))

enter image description here

Robert
  • 5,038
  • 1
  • 25
  • 43