[R] ggplot with sparse layout

Tom Wright tom at maladmin.com
Wed Jan 7 15:42:47 CET 2015


Thanks, this is pretty good. Unfortunately I made an error in generating
the sample dataframe, this code better represents the situation:
data<-data.frame(id=factor(rep(1:6,each=3)),
                  group=factor(rep(c('a','a','b','c','c','c'),each=3)),
                  x=runif(18,0,10),
                  y=rnorm(18,0,1))

I would like the first row to contain plots for id=1 & id=2, the second row
plots for id=3 and the third row for id=4:6




On Tue, Jan 6, 2015 at 5:58 PM, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be>
wrote:

> Dear Tom,
>
> Does
> ggplot(data,aes(x=x,y=y))+geom_point(aes(color=group))+facet_wrap(~group +
> id) gives what you need?
>
> Note that facet_grid by design aligns the subplots into rows and columns
> with the same level.
>
> Best regards,
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
> Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
> + 32 2 525 02 51
> + 32 54 43 61 85
> Thierry.Onkelinx at inbo.be
> www.inbo.be
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> ________________________________________
> Van: R-help [r-help-bounces at r-project.org] namens Tom Wright [
> tom at maladmin.com]
> Verzonden: dinsdag 6 januari 2015 22:13
> Aan: R. Help
> Onderwerp: [R] ggplot with sparse layout
>
> Hi,
>
> I would like to plot the following data such that each plot represents the
> data from a single id and the plots are grouped according to the group
> variable.
>
> data<-data.frame(id=factor(rep(1:6,each=3)),
>  group=factor(c('a','a','b','c','c','c')),
>  x=runif(18,0,10),
>  y=rnorm(18,0,1))
>
> The following ggplot nearly works but I would prefer to not plot the
> missing combinations, i.e. each row will be a different length.
>
> ggplot(data,aes(x=x,y=y))+geom_point(aes(color=group))+facet_grid(group~id)
>
> Is this possible using ggplot or will I need to craft something using grid?
>
> Thanks for any ideas.
> Tom
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
> Disclaimer<https://drupal.inbo.be/nl/disclaimer-mailberichten-van-het-inbo
> >
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list