Dear R-Users, I have a newbie-question about producing several plots with five variable pairs within in one code (loop). Problem: I define two objects, erveryone has five vectors (columns /variables): dimensionen <- data.frame(meinspss$attr_diff_gesamt, meinspss$finanz_diff_gesamt, meinspss$leist_diff_gesamt, meinspss$soz_diff_gesamt, meinspss$wert_diff_gesamt) gruppe <- data.frame(meinspss$R1_02, meinspss$R2_02, meinspss$R3_02,meinspss$R4_02,meinspss$R5_02) Now I would like to plot five similar graphs (beanplots, boxplots) for every pair of vectors (dimension by gruppe) . This works: box plot (dimensioned) - I receive a plot with 5 boxes. This does not work: boxplot (Dimensionen ~ Gruppe) - I would like to receive 5 plots I get the error message: Fehler in model.frame.default(formula = dimensionen ~ gruppe) : ung?ltiger Typ (list) f?r die Variable 'Dimensionen' Any help is very much appreciated! Happy Easter slyrs66 -- View this message in context: http://r.789695.n4.nabble.com/How-to-produce-serveral-plots-with-pairs-of-vectors-tp4540968p4540968.html Sent from the R help mailing list archive at Nabble.com.
Please do your homework first: Read at least the beginning of An Introduction to R or other R tutorial -- there are many. I say this because in your post below you do not seem to realize that R is case sensitive, and you do not seem to know the difference between a data frame and a column thereof and/or how to index them . Saying you are a newbie is not an excuse to avoid making a minimal effort to learn what you need to know. R is not a point and click social application and has a fairly steep (or more properly shallow, as Sarah Goslee, I believe, has noted) learning curve associated with it. If you prefer to avoid this, you may wish to try R Commander, Deducer, RStudio or other R GUI package to avoid this -- check the RGUI page on CRAN for what's there. Obviously, you get only limited functionality in GUI, but it may be sufficient for you. That said, something like for(i in 1:5) boxplot( dimensionen[,i] ~ gruppe[,i] ) should work, but you will probably be unhappy with the captioning and axis labels. Proper main titles and axis labels can be programatically built, but that requires you to learn a good deal more R than you appear to presently know. -- Bert On Sun, Apr 8, 2012 at 5:51 AM, slyrs66 <andreas.fahr at gmx.de> wrote:> Dear R-Users, > I have a newbie-question about producing several plots with five variable > pairs within in one code (loop). > > Problem: > I define two objects, erveryone has five vectors (columns /variables): > > dimensionen <- data.frame(meinspss$attr_diff_gesamt, > meinspss$finanz_diff_gesamt, meinspss$leist_diff_gesamt, > meinspss$soz_diff_gesamt, meinspss$wert_diff_gesamt) > gruppe <- data.frame(meinspss$R1_02, meinspss$R2_02, > meinspss$R3_02,meinspss$R4_02,meinspss$R5_02) > > Now I would like to plot five similar graphs (beanplots, boxplots) for every > pair of vectors (dimension by gruppe) . > > This works: box plot (dimensioned) - I receive a plot with 5 boxes. > > This does not work: boxplot (Dimensionen ~ Gruppe) - I would like to receive > 5 plots > > I get the error message: > Fehler in model.frame.default(formula = dimensionen ~ gruppe) : > ung?ltiger Typ (list) f?r die Variable 'Dimensionen' > > Any help is very much appreciated! > > Happy Easter > slyrs66 > > -- > View this message in context: http://r.789695.n4.nabble.com/How-to-produce-serveral-plots-with-pairs-of-vectors-tp4540968p4540968.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
David Winsemius
2012-Apr-08 15:33 UTC
[R] How to produce serveral plots with pairs of vectors
On Apr 8, 2012, at 8:51 AM, slyrs66 wrote:> Dear R-Users, > I have a newbie-question about producing several plots with five > variable > pairs within in one code (loop). > > Problem: > I define two objects, erveryone has five vectors (columns /variables): > > dimensionen <- data.frame(meinspss$attr_diff_gesamt, > meinspss$finanz_diff_gesamt, meinspss$leist_diff_gesamt, > meinspss$soz_diff_gesamt, meinspss$wert_diff_gesamt)This would probably be more readable: dimensionen <- with( meinspss , # creates an environment where the # column names can be used data.frame( attr_diff_gesamt, finanz_diff_gesamt, leist_diff_gesamt, soz_diff_gesamt, wert_diff_gesamt) ) (Spaces help the human brain separate elements.)> gruppe <- data.frame(meinspss$R1_02, meinspss$R2_02, > meinspss$R3_02,meinspss$R4_02,meinspss$R5_02)At this point providing the output of str(dimensionen) # and str(gruppe) .... would be very helpful.> > Now I would like to plot five similar graphs (beanplots, boxplots) > for every > pair of vectors (dimension by gruppe) . > > This works: box plot (dimensioned) - I receive a plot with 5 boxes.Not with that spelling it shouldn't, but perhaps with boxplot(dimensionen)> > This does not work: boxplot (Dimensionen ~ Gruppe) - I would like to > receive > 5 plots > > I get the error message: > Fehler in model.frame.default(formula = dimensionen ~ gruppe) : > ung?ltiger Typ (list) f?r die Variable 'Dimensionen'There are no objects named 'Dimensionen' or 'Gruppe', only ones named 'dimensionen' and 'gruppe'. And why are you putting entire dataframes on each side of a boxplot formula call? That seemed doomed to failure (even before the error message told you so) since the RHS of the formula is generally formed from vectors. You created 'gruppe' with 5 column vectors. Please explain: what sort of association exists between the various column vectors in 'dimensionen' and 'gruppe'? In other words: What are those Rn_02 variables and how do you expect to use 5 different _gruppe-ing variables with 5 _diff_erent variables in 'dimensionen' ? -- David Winsemius, MD West Hartford, CT