0

I'm trying to plot an scatter plot in R:

plot(cars$Hwy.MPG ~ cars$HP ,col=cars$Cyl , data=cars, pch=8)

and get an error:

Error in plot.xy(xy, type, ...) : 
  numerical color values must be >= 0, found -1

Cause I have values of '-1' in the column 'Cyl' . But I need those records too , and can't drop them.. how could I plot it with negative numbers too? Thanks

user2097810
  • 735
  • 6
  • 17
  • 25
  • 1
    Well since it's going to plot with some color, you'll have to pick a valid color number to replace the -1 with (I would guess -1 represents missing data). So pick a color to represent "missing" and replace -1 with that. – James King Apr 12 '14 at 17:22
  • Yeah... what colors *do* you want? I recommend against using different colors purely to discriminate different data levels unless you have only a very few levels. – Carl Witthoft Apr 12 '14 at 17:27
  • thanks , but Can I do that in the plot function? or I have to remove first records with -1 , than plot the graph , and after that add the records with -1. – user2097810 Apr 12 '14 at 17:27
  • Try it and see. Those sort of questions are very easily answered with a little experimentation. :-) – Carl Witthoft Apr 12 '14 at 18:19
  • Hi , I did that with the first way (delete -1 , plot , add -1) but it's look bad. so I want to know if there is way to plot the graph with negative values.. – user2097810 Apr 12 '14 at 18:28
  • why not try: plot(cars$Hwy.MPG ~ cars$HP ,col=1+cars$Cyl , data=cars, pch=8) – amit Apr 13 '14 at 09:30

0 Answers0