2015-11-26 52 views
0

我有一個散點圖,我需要添加一個圖例。它看起來像代碼是正確的,但它沒有被添加。有什麼想法嗎?需要幫助添加圖例使用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")) 
+0

你好的東西!你能否提供一個可重複的例子?我們沒有'舞蹈'對象。 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –

回答

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

+0

這工作!謝謝。 – Vixxen81