[R] How to produce serveral plots with pairs of vectors

David Winsemius dwinsemius at comcast.net
Sun Apr 8 17:33:25 CEST 2012


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



More information about the R-help mailing list