tags:

views:

55

answers:

1
+1  Q: 

Barplot Error in R

Hello Everyone,

I recently created a barplot in R using some sample data with no trouble. Then I tried it again using the real data which was exactly the same as the sample data except there was more of it. The problem is now I get this error:

Error in barplot.default(table(datafr)) : 
   'height' must be a vector or a matrix

I don't know if this is of help but when I print out the table these are what the last lines look like.

33333  2010-09-13-19:25:50.206                             Google Chrome-#135   NA
  [ reached getOption("max.print") -- omitted 342611 rows ]]

Is it possible that this is too much data to process? Any suggestion as to how I can fix this?

Thanks :)


EDIT 1

Hey Joris,

Here is the info from str(datafr) :

'data.frame':   375944 obs. of  3 variables:
 $ TIME     : Factor w/ 375944 levels "2010-09-11-19:28:34.680 ",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ FOCUS.APP: Factor w/ 107 levels " Finder-#101  ",..: 3 3 3 3 3 3 3 3 1 1 ...  
 $ X        : logi  NA NA NA NA NA NA ...

and from traceback()

3: stop("'height' must be a vector or a matrix")
2: barplot.default(table(datafr))
1: barplot(table(datafr))

I also ran the other command you told me, but the feedback was super verbose; too much to print here. Let me know if you need any other info or if the last information was really important I can figure out a way to post it.

Thanks,

+1  A: 

Ah, that solves the problem : you have 3 dimensions in your table, barplot can't deal with that. Take the 2 columns you want to use for the barplot function, eg:

# sample data
Df <- data.frame(
  TIME = as.factor(seq.Date(as.Date("2010-09-11"),as.Date("2010-09-20"),by="day")),
  FOCUS.APP = as.factor(rep(c("F101","F102"),5)),
  X = sample(c(TRUE,FALSE,NA),10,r=T)
)

# make tables
T1 <- table(Df)
T2 <- table(Df[,-3])

# plot tables
barplot(T1)
barplot(T2)

This said, that plot must look interesting to say the least. I don't know what you try to do, but I'd say that you might to reconsider your approach to it.

Joris Meys