[R] plotting the regression coefficients

greg holly mak.hholly at gmail.com
Mon Feb 12 19:07:12 CET 2018


Hi Petr and Richard;

Thanks for your responses and supports.  I just faced a different problem.
I have the following R codes and work well.

p <- ggplot(a, aes(x=Phenotypes, y=Metabolites, size=abs(Beta),
colour=factor(sign(Beta)))) +
theme(axis.text=element_text(size = 5))
p1<-p+geom_point()
p2<-p1+theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          panel.border = element_blank(),
          axis.ticks = element_blank())

p3<-p2+theme(panel.grid.major = element_blank(), panel.grid.minor =
element_blank(),
panel.background = element_blank(), axis.line = element_line(colour =
"black"))

p4<-p3+scale_color_manual(breaks = c("-1", "0", "1"),
                        values=c("darkblue", "green", "red"))


*My question is:*
What if I was to repeat the analysis and standardize the beta (z-score) so
they are comparable across phenotypes (I have 8 phenotypes). We could then
“bin” the betas to represent shades of red and blue.

Regards,

Greg


On Mon, Feb 12, 2018 at 8:10 PM, Richard M. Heiberger <rmh at temple.edu>
wrote:

> Petr, there was a thinko in your response.
>
>
> tmp <- data.frame(m=factor(letters[1:4]), n=1:4)
> tmp
> tmp$m <- factor(tmp$m, levels=c("c","b","a","d")) ## right
> tmp[order(tmp$m),]
>
> tmp <- data.frame(m=factor(letters[1:4]), n=1:4)
> levels(tmp$m) <- c("c","b","a","d") ## wrong
> tmp[order(tmp$m),]
>
> changing levels directly changes the names only, not the ordering.
> You must redefine the factor to retain the relationship of factor
> names with the numerical values.
>
> Rich
>
>
> On Mon, Feb 12, 2018 at 3:49 AM, PIKAL Petr <petr.pikal at precheza.cz>
> wrote:
> > Hi
> >
> > After melt you can change levels of your factor variable. Again with the
> toy example.
> >
> >> levels(temp$variable)
> > [1] "y1" "y2" "y3" "y4"
> >> levels(temp$variable) <- levels(temp$variable)[c(2,4,1,3)]
> >> levels(temp$variable)
> > [1] "y2" "y4" "y1" "y3"
> >>
> >
> > And you will get graphs with this new levels ordering.
> >
> > Cheers
> > Petr
> >
> > From: greg holly [mailto:mak.hholly at gmail.com]
> > Sent: Monday, February 12, 2018 8:52 AM
> > To: PIKAL Petr <petr.pikal at precheza.cz>
> > Cc: r-help mailing list <r-help at r-project.org>
> > Subject: Re: [R] plotting the regression coefficients
> >
> > Hi Petr;
> >
> > Thanks so much. This is great! Although last Sunday, alternatively, I
> have solved the problem using the following statement at the very end of
> the program.
> >
> >  ggsave('circle.pdf', p4, height = 70, width = 8, device=pdf, limitsize
> = F, dpi=300).
> >
> > This works very well too.
> >
> > Asa my categorical variables are in my Y axis, my R program reorders the
> names on Y-axis. However, I would like have and plot output with the names
> as they are. Is there any way to have plot without ordering the names of
> variables on Y-axis?
> >
> > Regards,
> > Greg.
> >
> > On Mon, Feb 12, 2018 at 10:12 AM, PIKAL Petr <petr.pikal at precheza.cz<
> mailto:petr.pikal at precheza.cz>> wrote:
> > Hi
> >
> > Maybe there are other ways but I would split data to several chunks e.g.
> in list and use for cycle to fill multipage pdf.
> >
> > With the toy data something like
> >
> > library(reshape2)
> > library(ggplot2)
> > temp <- melt(temp)
> > temp.s<-split(temp, cut(1:nrow(temp), 2))
> >
> > pdf("temp.pdf")
> > for (i in 1: length(temp.s)) {
> > p <- ggplot(temp.s[[i]], aes(x=par1, y=variable, size=abs(value),
> colour=factor(sign(value))))
> > print(p+geom_point())
> > }
> > dev.off()
> >
> > But the real code partly depends on your real data.
> >
> > Cheers
> > Petr
> >
> > From: greg holly [mailto:mak.hholly at gmail.com<mailto:
> mak.hholly at gmail.com>]
> > Sent: Saturday, February 10, 2018 9:05 PM
> >
> > To: PIKAL Petr <petr.pikal at precheza.cz<mailto:petr.pikal at precheza.cz>>
> > Cc: r-help mailing list <r-help at r-project.org<mailto:r
> -help at r-project.org>>
> > Subject: Re: [R] plotting the regression coefficients
> >
> > Hi Peter;
> >
> > The R code you provided works very well. Once again thanks so much for
> this. The number of variables in my data set that should appear on the
> y-axis is 733 and they are not numerical (for example the name of one
> variable is palmitoyl-arachidonoyl-glycerol (16:0/20:4) [1]*. So, the
> plot looks very messy in one page. How can I make the plot to print out on
> multiple pages?
> >
> > Regards,
> >
> > Greg
> >
> > On Thu, Feb 8, 2018 at 4:33 PM, greg holly <mak.hholly at gmail.com<mailto:
> mak.hholly at gmail.com>> wrote:
> > Hi Petr;
> >
> > Thanks so much. Exactly this is what I need. I will play to change color
> and so on but this backbound is perfect to me. I do appreciate your help
> and support.
> >
> > Regards,
> > Greg
> >
> > On Thu, Feb 8, 2018 at 1:29 PM, PIKAL Petr <petr.pikal at precheza.cz<
> mailto:petr.pikal at precheza.cz>> wrote:
> > Hi
> > I copied your values to R, here it is
> >
> >> dput(temp)
> >
> > temp <- structure(list(par1 = structure(1:4, .Label = c("x1", "x2", "x3",
> > "x4"), class = "factor"), y1 = c(-0.19, 0.45, -0.09, -0.16),
> >     y2 = c(0.4, -0.75, 0.14, -0.01), y3 = c(-0.06, -8.67, 1.42,
> >     2.21), y4 = c(0.13, -0.46, 0.06, 0.06)), .Names = c("par1",
> > "y1", "y2", "y3", "y4"), class = "data.frame", row.names = c(NA,
> > -4L))
> >
> > For plotting it need to be reshaped
> >
> > library(reshape2)
> > library(ggplot2)
> >
> > temp <- melt(temp)
> > p <- ggplot(temp, aes(x=par1, y=variable, size=abs(value),
> colour=factor(sign(value))))
> > p+geom_point()
> >
> > Is this what you wanted?
> >
> > Cheers
> > Petr
> > And preferably do not post in HTML, the email content could be scrambled.
> >
> > From: greg holly [mailto:mak.hholly at gmail.com<mailto:
> mak.hholly at gmail.com>]
> > Sent: Thursday, February 8, 2018 9:23 AM
> > To: PIKAL Petr <petr.pikal at precheza.cz<mailto:petr.pikal at precheza.cz>>
> > Cc: r-help mailing list <r-help at r-project.org<mailto:r
> -help at r-project.org>>
> > Subject: Re: [R] plotting the regression coefficients
> >
> > Hi Petr;
> >
> > Thanks for your reply. It is much appreciated. A small example is given
> below for 4 independent and 4 dependent variables only. The values given
> are regression coefficients.I have looked ggplot documents before writing
> to you. Unfortunately, I could not figure out as my experience in ggplot is
> ignorable
> >
> > Regards.
> > Greg
> >
> > y1 y2 y3 y4
> > x1 -0.19 0.40 -0.06 0.13
> > x2 0.45 -0.75 -8.67 -0.46
> > x3 -0.09 0.14 1.42 0.06
> > x4 -0.16 -0.01 2.21 0.06
> >
> >
> > On Thu, Feb 8, 2018 at 10:19 AM, PIKAL Petr <petr.pikal at precheza.cz<
> mailto:petr.pikal at precheza.cz>> wrote:
> > Hi
> >
> > Example, example, example - preferably working.
> >
> > Wild guess - did you try ggplot?
> >
> > Cheers
> > Petr
> >
> >
> >> -----Original Message-----
> >> From: R-help [mailto:r-help-bounces at r-project.org<mailto:r-help-
> bounces at r-project.org>] On Behalf Of greg holly
> >> Sent: Thursday, February 8, 2018 8:14 AM
> >> To: r-help mailing list <r-help at r-project.org<mailto:r
> -help at r-project.org>>
> >> Subject: [R] plotting the regression coefficients
> >>
> >> Hi Dear all;
> >>
> >> I would like to create a plot for regression coefficients with each
> independent
> >> variable (x) along the side and the phenotypes (y) across the top (as
> given
> >> below). For each data point, direction and magnitude of effect could be
> color
> >> and significance could be the size of the circle? Is this possible?
> >>
> >>
> >> I would greatly be appreciated your help.
> >>
> >> Thanks,
> >>
> >> Greg
> >>
> >>
> >>
> >>   y1 y2 y3 y4 y5 y6
> >> x1
> >> x2
> >> x3
> >> x4
> >> x5
> >> x6
> >> x7
> >> x8
> >> x9
> >> x10
> >> x11
> >> x12
> >> x13
> >> x14
> >> x15
> >> x16
> >> x17
> >> .
> >> .
> >>
> >
> >
> > ________________________________
> > Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou
> určeny pouze jeho adresátům.
> > Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě
> neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie
> vymažte ze svého systému.
> > Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento
> email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> > Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou
> modifikacemi či zpožděním přenosu e-mailu.
> >
> > V případě, že je tento e-mail součástí obchodního jednání:
> > - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření
> smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
> > - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně
> přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze
> strany příjemce s dodatkem či odchylkou.
> > - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve
> výslovným dosažením shody na všech jejích náležitostech.
> > - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za
> společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn
> nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto
> emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich
> existence je adresátovi či osobě jím zastoupené známá.
> >
> > This e-mail and any documents attached to it may be confidential and are
> intended only for its intended recipients.
> > If you received this e-mail by mistake, please immediately inform its
> sender. Delete the contents of this e-mail with all attachments and its
> copies from your system.
> > If you are not the intended recipient of this e-mail, you are not
> authorized to use, disseminate, copy or disclose this e-mail in any manner.
> > The sender of this e-mail shall not be liable for any possible damage
> caused by modifications of the e-mail or by delay with transfer of the
> email.
> >
> > In case that this e-mail forms part of business dealings:
> > - the sender reserves the right to end negotiations about entering into
> a contract in any time, for any reason, and without stating any reasoning.
> > - if the e-mail contains an offer, the recipient is entitled to
> immediately accept such offer; The sender of this e-mail (offer) excludes
> any acceptance of the offer on the part of the recipient containing any
> amendment or variation.
> > - the sender insists on that the respective contract is concluded only
> upon an express mutual agreement on all its aspects.
> > - the sender of this e-mail informs that he/she is not authorized to
> enter into any contracts on behalf of the company except for cases in which
> he/she is expressly authorized to do so in writing, and such authorization
> or power of attorney is submitted to the recipient or the person
> represented by the recipient, or the existence of such authorization is
> known to the recipient of the person represented by the recipient.
> >
> >         [[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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list