-2

I am fairly new to R and What I'd like to do is to scatter plot by category. I have a data set with 5 category (Item_nbr) and 19 variables. I want to have scatter plot for each category separately not in the same graph with different color. I mean generate 5 scatter plot. My data is :

Date         Units  avgdir  Item_nbr   tmax
1/1/2012       0     0.5      1         50
1/1/2012       2     0.2      2         40
1/1/2012       3     0.1      3         60
1/1/2012       10    0.7      4         70
1/1/2012        5    0.2      5         80
1/2/2012        6    0.8      1         90
1/2/2012        11   0.8      2         40
1/2/2012        12   0.8      3         70
1/2/2012        9    0.8      4         60
1/2/2012        8    0.8      5         70
............

Now How can I 5 scatter plot to plot units column in each of them.

Elham
  • 1
  • 1
  • 2

1 Answers1

0

Simplest solution:

for(i in unique(data$Item_nbr))
  plot(Units ~ avgdir, data[data$Item_nbr == i, ])
Andrey Kolyadin
  • 1,301
  • 10
  • 14
  • Thanks I run it but I have this error "object of type 'closure' is not subsettable" and It gave me one plot not 5 plot. If I have other columns (17 columns extra than avgdir) Can i use the same solution – Elham Dec 02 '16 at 14:55
  • Rename every data to your dsata.frame name (AllItems, i suppose?). – Andrey Kolyadin Dec 02 '16 at 22:09