[R] facet plot

Dennis Murphy djmuser at gmail.com
Fri Feb 1 09:58:28 CET 2013


Hi:

Try

DF <- structure(list(Gene = structure(1:5, .Label = c("NM_001001130",
"NM_001001144", "NM_001001152", "NM_001001160", "NM_001001176"
), class = "factor"), T0h = c(68L, 0L, 79L, 1L, 0L), T0.25h = c(95L,
1L, 129L, 1L, 0L), T0.5h = c(56L, 4L, 52L, 2L, 0L), T1h = c(43L,
0L, 50L, 0L, 0L), T2h = c(66L, 1L, 24L, 0L, 0L), T3h = c(62L,
1L, 45L, 1L, 0L), T6h = c(68L, 1L, 130L, 0L, 0L), T12h = c(90L,
4L, 154L, 0L, 0L), T24h = c(63L, 1L, 112L, 0L, 0L), T48h = c(89L,
2L, 147L, 1L, 0L)), .Names = c("Gene", "T0h", "T0.25h", "T0.5h",
"T1h", "T2h", "T3h", "T6h", "T12h", "T24h", "T48h"), class =
"data.frame", row.names = c("1", "2", "3", "4", "5"))

library(reshape2)
library(ggplot2)

# stack the time-related variables by Gene
Dfm <- melt(DF, id = "Gene")
# extract the numeric time values
Dfm$time <- as.numeric(gsub("[a-zA-Z]", "", as.character(Dfm$variable)))

ggplot(Dfm, aes(x = time, y = value)) + geom_point() + facet_wrap(~ Gene)


Dennis

On Thu, Jan 31, 2013 at 2:37 AM, Jose Iparraguirre
<Jose.Iparraguirre at ageuk.org.uk> wrote:
> Hi Robin,
>
> You didn't provide the list with a clear structure of your data, but I hope I understood it properly. If not, it'd be easy for you to adapt what follows.
>
> I guess your data looks like this:
>
>            Gene  T0h T0.25h T0.5h  T1h  T2h  T3h  T6h T12h T24h T48h
> 1  NM_001001130   68     95    56   43   66   62   68   90   63   89
> 2  NM_001001144    0      1     4    0    1    1    1    4    1    2
> 3  NM_001001152   79    129    52   50   24   45  130  154  112  147
> 4  NM_001001160    1      1     2    0    0    1    0    0    0    1
> 5  NM_001001176    0      0     0    0    0    0    0    0    0    0
> ...
>
> If this is the case, first reshape your data (say, gene.df) to a long format:
>
>             Gene Time
> 1   NM_001001130   68
> 2   NM_001001144    0
> 3   NM_001001152   79
> 4   NM_001001160    1
> 5   NM_001001176    0
> 6   NM_001001177    1
> 7   NM_001001178    0
> 8   NM_001001179    0
> 9   NM_001001182 4691
> ...
>
> Then, you create the ggplot:
>
>> sp <- ggplot(gene.df, aes(x=Gene, y=Time)) + geom_point(shape=1)
>
> And use the function facet_wrap():
>
>> sp + facet_wrap( ~ Gene,ncol=3)
>
> You can set a different number of columns and a different shape for the markers, of course.
>
> Hope this helps.
>
> Regards,
>
> José
>
>
> José Iparraguirre
> Chief Economist
> Age UK
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Robin Mjelle
> Sent: 31 January 2013 09:06
> To: r-help at r-project.org
> Subject: [R] facet plot
>
> Hi all,
>
> I want to plot a facet plot with column names as x and column values as y.
> One plot for each row. here is part of my dataset:
>
>     Gene T0h T0.25h T0.5h T1h T2h T3h T6h T12h T24h T48h  NM_001001130 68 95
> 56 43 66 62 68 90 63 89  NM_001001144 0 1 4 0 1 1 1 4 1 2  NM_001001152 79
> 129 52 50 24 45 130 154 112 147  NM_001001160 1 1 2 0 0 1 0 0 0 1
> NM_001001176 0 0 0 0 0 0 0 0 0 0  NM_001001177 1 3 2 3 0 1 1 0 2 0
> NM_001001178 0 0 0 0 0 0 0 0 0 0  NM_001001179 0 0 0 0 0 0 0 0 0 0
> NM_001001180 1 0 0 1 0 0 0 0 0 0  NM_001001181 350 539 424 470 441 451 554
> 553 419 548  NM_001001182 4691 6458 5686 6761 5944 4486 6030 5883 6009 7552
> NM_001001183 22 23 12 21 25 17 34 40 33 32  NM_001001184 138 147 111 100 54
> 61 61 77 57 99  NM_001001185 2 3 4 3 4 5 9 2 4 4  NM_001001186 231 337 187
> 168 148 178 275 319 181 279
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
> Wrap Up and Run 10k is back!
>
> Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by
> signing up now:
>
> http://www.ageuk.org.uk/10k
>
>                  Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds |
>                                  Tatton Park, Cheshire | Southampton | Coventry
>
>
>
> Age UK Improving later life
>
> http://www.ageuk.org.uk
>
>
>
>
> -------------------------------
> Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798).
> Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.
>
> For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer
> Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health
> cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and
> regulated by the Financial Services Authority.
> ------------------------------
>
> This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are
> addressed. If you receive a message in error, please advise the sender and delete immediately.
>
> Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not
> necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing
> through its network and may block or modify mails which are deemed to be unsuitable.
>
> Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged
> on 1st April 2009.  Together they have formed the Age UK Group, dedicated to improving the lives of people in later life.  The three national
> Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities:
> Age Scotland, Age NI, Age Cymru.
>
>
>
>
>
>
>
>
>
>
> ______________________________________________
> 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.



More information about the R-help mailing list