-2

I'm an R beginner attempting to do what I figured (erroneously) would be a beginner-type task: produce a simple plot of means/standard deviations for multiple survey questions (vectors), grouped by a second variable (say, group).

So I am reading variables (say, q1-q10) into R from Stata and have even managed to melt the data following this suggestion.

What I would like is essentially the graph presented in the solution:

However, my data contain missing values (NA), and the NUMBER of missing values varies by question. So when I try to use ggplot to plot the 'melted' data, I get an error saying the vector lengths do not match.

  • 2
    Without an example of your data and some code showing what you tried to do, your question is almost impossible to answer. For more info on generating a reproducible example see: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Jan van der Laan Nov 17 '15 at 09:11
  • Like I said, I am interested in how one can produce a specific type of plot -- namely, plot of means/standard deviations for multiple vectors grouped by a second variable, all of which contain missing values -- rather than code for a specific example. – user5570823 Nov 17 '15 at 09:34
  • 1
    Please re-read @JanvanderLaan comment. You should provide a (simulated) dataset and offending code. – Roman Luštrik Nov 17 '15 at 09:51

1 Answers1

0

Well, suppose that your variables q1-q10 are separated, then you should merge them into a data frame df:

df <- data.frame(q1, q2, ...,q10)

And then you can clean it such that you only have complete cases, i.e. only observations without NA:

df <- df[complete.cases(df),]

Afterwards, you should not have problems with ggplot.

S. Elzwawi
  • 531
  • 12
  • 14