Skip to content
Prev 275542 / 398506 Next

Help with a scatter plot

On 10/26/2011 05:48 PM, RanRL wrote:
Hi RanRL,
I swapped the colors and product names, but this rather inelegant code 
might do what you want:

ranrl<-read.table("ranrl.dat",header=TRUE)
plot(ranrl$Price,ranrl$StoreC,ylim=range(ranrl[,3:5],na.rm=TRUE),
  type="n",xlab="Price",ylab="Number sold")
text(ranrl$Price[1],ranrl[1,3:5],
  paste("ProdA",names(ranrl)[3:5],sep="\n"),
  col="red")
text(ranrl$Price[2],ranrl[2,3:5],
  paste("ProdA",names(ranrl)[3:5],sep="\n"),
  col="green")
text(ranrl$Price[3],ranrl[3,3:5],
  paste("ProdA",names(ranrl)[3:5],sep="\n"),
  col="blue")
text(ranrl$Price[4],ranrl[4,3:5],
  paste("ProdA",names(ranrl)[3:5],sep="\n"),
  col="yellow")
text(ranrl$Price[5],ranrl[5,3:5],
  paste("ProdB",names(ranrl)[3:5],sep="\n"),
  col="blue")
text(ranrl$Price[6],ranrl[6,3:5],
  paste("ProdC",names(ranrl)[3:5],sep="\n"),
  col="green")

Jim