[R] a replace for subset

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Sat Apr 16 16:03:22 CEST 2016


On Sat, 16 Apr 2016, ch.elahe via R-help wrote:

> -Thank you James, well the problem of my type of data is that there can 
> be many possible subsets and therefore plots, and I want to 
> automatically generate them, and facet_wrap does not give me all the 
> possible cases

Not true.

It may get cramped, but it does give you all of the cases listed in the 
levels of the factor you plot with. If you specify a vector of character 
strings then ggplot will automatically convert it to a factor using only 
those cases present in the data. You can use the "factor" function to 
specify how you want the data represented more precisely than this 
automatic conversion will represent it. Read ?factor.

Note that if you have missing cases throughout, you may encounter 
difficulties plotting some graphs due to not having any data.

>
> On Saturday, April 16, 2016 6:01 AM, James C. Whanger <james.whanger at gmail.com> wrote:
>
> Would facet_wrap or facet_grid give you what you want?
>
> On Sat, Apr 16, 2016 at 8:45 AM, ch.elahe via R-help <r-help at r-project.org> wrote:
>
> Hi,
>> I have a data set (mydata), which a part of this is like the following:
>>
>>
>> 'data.frame':   36190 obs. of 16 variables:
>> $ RE                    : int  38 41 11 67 30 18 38 41 41 30 ...
>> $ LU                     : int  4200 3330 530 4500 3000 1790 4700 3400 3640 4000 ...
>> $ COUNTRY        : Factor w/ 4 levels "DE","FR","JP", "FR"?
>> $Light                  : Factor w/2 levels   "ON","OFF","ON", ?.
>> $OR                     : Factor w/2 levels   "S","T","S",?.
>> $PAT                  : Factor w/3 levels   "low", "high", "middle",?.
>>
>>
>> Now I want to plot RE vs LU with ggplot2 for all the possible cases, I 
>> know how to do subsetting for the data but I want to know is there any 
>> shorter way to do that? For example I want to have a plot for RE vs LU 
>> for (COUNTRY= FR, Light=off, OR=S, PAT=low) and one for (COUNTRY= FR, 
>> Light=on, OR=S, PAT=high) and ?., as you see doing subset is time 
>> consuming, is there any other way?
>> Thank you for any help.
>> Elahe

[...]

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k



More information about the R-help mailing list