-1

I'm trying to plot some data for eventual statistical analysis. Currently I am using ggvis to plot the data because I saw some cool interactivity and ease of use the function has.

Anyways, this is the code that is giving me the error Error: length(x) not equal to 1:

ggvis(myfile, myfile$Shipment.Date, myfile$Act.Ctns)

sample data

          Shipment.Date                  Act.Ctns
3326      3/3/2015  Wm Eu Apple 2L       60
3327      3/3/2015 Tp Euro 2 Layer      420
3328      3/3/2015     Tpe 3-Layer       80
3329      3/3/2015        14/3 Bgs      145
3330      3/4/2015             T/P      196
3331      3/4/2015  Wm Eu Apple 2L    1,260
3332      3/4/2015 Tp Euro 2 Layer      360
3333      3/4/2015        14/3 Bgs    1,355

here is some sample data, I just printed myfile and took a copy of it. I'm completely new to R unclear how to fix this issue. Please let me know if I need to convert a variable or do something else for ggvis to work. Thanks!

I've looked at ?ggvis, but it appears I've met all the criteria for the funtion, and watched someone do the exact same thing with a similar time series data set in another video.

jlhoward
  • 58,004
  • 7
  • 97
  • 140
RFC_DA
  • 3
  • 4
  • 1
    we need to see your code, we need some example data. – Shawn Mehan Sep 11 '15 at 17:19
  • Have you tried making your code mirror what you read in the Examples section of `?ggvis`? All the example code contains tildes and no dollar signs, for example, which I don't see in your code. – aosmith Sep 11 '15 at 17:44

1 Answers1

0

You're specifying the aesthetics incorrectly. Try

ggvis(myfile, ~Shipment.Date, ~Act.Ctns)

as in:

ggvis(mtcars, ~mpg, ~wt)

jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • So when I run the code the way you told me to, which is also the way I saw in a new video, I get the following error: Error in f(vis, ...) : y variable (weights) must be numeric. – RFC_DA Sep 11 '15 at 17:52
  • Well, is `myfile$Act.Ctns` numeric? I think there may be a problem with the waay to are importing your data. What is the output of `sapply(myfile,class)`? How about `summary(myfile)`? – jlhoward Sep 11 '15 at 17:57
  • Okay, all 3 are factors, I just converted the cartons to numeric using as.numeric() and it finally plots so thanks! However, I have a new problem, which may require a new question instead of an extension edit of this one...my graph does not include the shipment dates along the x axis, only 1 bar with no labels – RFC_DA Sep 11 '15 at 18:01
  • You could try `myfile$Shipment.Date <- as.Date(myfile$Shipment.Date, format="%m/%d/%Y")` but I'm worried about all that random text. Which column does it belong to? – jlhoward Sep 11 '15 at 18:09
  • That actually worked! Running myfile$Shipment.date also prints all the dates with no NA's or missing dates it seems so I think all is good. Thank you so much! – RFC_DA Sep 11 '15 at 18:12
  • If it works, great. But you should know that you can't convert a factor to numeric using `as.numeric(...)`. That returns the codes, not the levels. You have to use `as.numeric(as.character(...))`. – jlhoward Sep 11 '15 at 20:07