需要帮助使用R向Scatter Plot添加图例

时间:2015-11-26 21:48:25

标签: r

我有一个散点图我需要添加一个图例。看起来代码是正确的,但它没有被添加。有什么想法吗?

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"))

1 个答案:

答案 0 :(得分:0)

由于缺乏信息而难以回答,但您可以尝试这样的事情

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