Re: [R] Help with regular expressions

2018-02-12 Thread Ulrik Stervbo
I think I would replace all , with . and subsequently replace all first .
with , using ^\\.

x <- gsub(",", ".", x)
gsub("^\\.", ",", x)

It's not so elegant, but it is easier to understand than backreferences and
complex regex.

Best,
Ulrik

On Tue, 13 Feb 2018, 03:38 Boris Steipe,  wrote:

> You can either use positive lookahead/lookbehind - but support for that is
> a bit flaky. Or write a proper regex, and use
> backreferences to keep what you need.
>
> R > x <- "abc 1,1 ,1 1, x,y 2,3 "
>
> R > gsub("(\\d),(\\d)", "\\1.\\2", x, perl = TRUE)
> [1] "abc 1.1 ,1 1, x,y 2.3 "
>
>
> B.
>
>
>
> > On Feb 12, 2018, at 9:34 PM, Jim Lemon  wrote:
> >
> > Hi Dennis,
> > How about:
> >
> >
> > # define the two values to search for
> > x<-2
> > y<-3
> > # create your search string and replacement string
> > repstring<-paste(x,y,sep=",")
> > newstring<-paste(x,y,sep=".")
> > # this is the string that you want to change
> > thetastring<-"SIGMA(2,3)"
> > sub(repstring,newstring,thetastring)
> > [1] "SIGMA(2.3)"
> >
> > Use gsub if you want to change multiple values
> >
> > Jim
> >
> > On Tue, Feb 13, 2018 at 1:22 PM, Dennis Fisher 
> wrote:
> >> R 3.4.2
> >> OS X
> >>
> >> Colleagues
> >>
> >> I would appreciate some help with regular expressions.
> >>
> >> I have string that looks like:
> >>" ITERATION  ,THETA1 ,THETA2
>  ,THETA3 ,THETA4 ,THETA5
>  ,THETA6 ,THETA7 ,SIGMA(1,1)
>  ,SIGMA(2,1) ,SIGMA(2,2)”
> >>
> >> In the entries that contain:
> >>(X,Y)   # for example, SIGMA(1,1)
> >> I would like to replace the comma with a period, e.g., SIGMA(1.1) but
> NOT the other commas
> >>
> >> The end-result would be:
> >>" ITERATION  ,THETA1 ,THETA2
>  ,THETA3 ,THETA4 ,THETA5
>  ,THETA6 ,THETA7 ,SIGMA(1.1)
>  ,SIGMA(2.1) ,SIGMA(2.2)”
> >>
> >> Can someone provide the regular expression code to accomplish this?
> >> Thanks.
> >>
> >> Dennis
> >>
> >> Dennis Fisher MD
> >> P < (The "P Less Than" Company)
> >> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> >> www.PLessThan.com
> >>
> >> __
> >> R-help@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.
> >
> > __
> > R-help@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.
>
> __
> R-help@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]]

__
R-help@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.


Re: [R] Help with regular expressions

2018-02-12 Thread Boris Steipe
You can either use positive lookahead/lookbehind - but support for that is a 
bit flaky. Or write a proper regex, and use
backreferences to keep what you need.

R > x <- "abc 1,1 ,1 1, x,y 2,3 "

R > gsub("(\\d),(\\d)", "\\1.\\2", x, perl = TRUE)
[1] "abc 1.1 ,1 1, x,y 2.3 "


B.



> On Feb 12, 2018, at 9:34 PM, Jim Lemon  wrote:
> 
> Hi Dennis,
> How about:
> 
> 
> # define the two values to search for
> x<-2
> y<-3
> # create your search string and replacement string
> repstring<-paste(x,y,sep=",")
> newstring<-paste(x,y,sep=".")
> # this is the string that you want to change
> thetastring<-"SIGMA(2,3)"
> sub(repstring,newstring,thetastring)
> [1] "SIGMA(2.3)"
> 
> Use gsub if you want to change multiple values
> 
> Jim
> 
> On Tue, Feb 13, 2018 at 1:22 PM, Dennis Fisher  wrote:
>> R 3.4.2
>> OS X
>> 
>> Colleagues
>> 
>> I would appreciate some help with regular expressions.
>> 
>> I have string that looks like:
>>" ITERATION  ,THETA1 ,THETA2  
>>,THETA3 ,THETA4 ,THETA5 
>> ,THETA6 ,THETA7 ,SIGMA(1,1) 
>> ,SIGMA(2,1) ,SIGMA(2,2)”
>> 
>> In the entries that contain:
>>(X,Y)   # for example, SIGMA(1,1)
>> I would like to replace the comma with a period, e.g., SIGMA(1.1) but NOT 
>> the other commas
>> 
>> The end-result would be:
>>" ITERATION  ,THETA1 ,THETA2  
>>,THETA3 ,THETA4 ,THETA5 
>> ,THETA6 ,THETA7 ,SIGMA(1.1) 
>> ,SIGMA(2.1) ,SIGMA(2.2)”
>> 
>> Can someone provide the regular expression code to accomplish this?
>> Thanks.
>> 
>> Dennis
>> 
>> Dennis Fisher MD
>> P < (The "P Less Than" Company)
>> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>> www.PLessThan.com
>> 
>> __
>> R-help@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.
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] Help with regular expressions

2018-02-12 Thread David Winsemius

> On Feb 12, 2018, at 6:22 PM, Dennis Fisher  wrote:
> 
> R 3.4.2
> OS X
> 
> Colleagues
> 
> I would appreciate some help with regular expressions.
> 
> I have string that looks like:
>   " ITERATION  ,THETA1 ,THETA2
>  ,THETA3 ,THETA4 ,THETA5 
> ,THETA6 ,THETA7 ,SIGMA(1,1) 
> ,SIGMA(2,1) ,SIGMA(2,2)”
> 
> In the entries that contain:
>   (X,Y)   # for example, SIGMA(1,1)
> I would like to replace the comma with a period, e.g., SIGMA(1.1) but NOT the 
> other commas
> 
> The end-result would be:
>   " ITERATION  ,THETA1 ,THETA2
>  ,THETA3 ,THETA4 ,THETA5 
> ,THETA6 ,THETA7 ,SIGMA(1.1) 
> ,SIGMA(2.1) ,SIGMA(2.2)”
> 
> Can someone provide the regular expression code to accomplish this?

gsub( "([(]\\d+)([,])(\\d+[)])", "\\1.\\3", x)\
#---
[1] "ITERATION  ,THETA1 ,THETA2 
,THETA3 ,THETA4 ,THETA5 ,THETA6 
,THETA7 ,SIGMA(1.1) ,SIGMA(2.1) 
,SIGMA(2.2)"


> Thanks.
> 
> Dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
> 
> __
> R-help@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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@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.


Re: [R] Help with regular expressions

2018-02-12 Thread Jim Lemon
Hi Dennis,
How about:


# define the two values to search for
x<-2
y<-3
# create your search string and replacement string
repstring<-paste(x,y,sep=",")
newstring<-paste(x,y,sep=".")
# this is the string that you want to change
thetastring<-"SIGMA(2,3)"
sub(repstring,newstring,thetastring)
[1] "SIGMA(2.3)"

Use gsub if you want to change multiple values

Jim

On Tue, Feb 13, 2018 at 1:22 PM, Dennis Fisher  wrote:
> R 3.4.2
> OS X
>
> Colleagues
>
> I would appreciate some help with regular expressions.
>
> I have string that looks like:
> " ITERATION  ,THETA1 ,THETA2  
>,THETA3 ,THETA4 ,THETA5 
> ,THETA6 ,THETA7 ,SIGMA(1,1) 
> ,SIGMA(2,1) ,SIGMA(2,2)”
>
> In the entries that contain:
> (X,Y)   # for example, SIGMA(1,1)
> I would like to replace the comma with a period, e.g., SIGMA(1.1) but NOT the 
> other commas
>
> The end-result would be:
> " ITERATION  ,THETA1 ,THETA2  
>,THETA3 ,THETA4 ,THETA5 
> ,THETA6 ,THETA7 ,SIGMA(1.1) 
> ,SIGMA(2.1) ,SIGMA(2.2)”
>
> Can someone provide the regular expression code to accomplish this?
> Thanks.
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> __
> R-help@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.

__
R-help@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.


[R] Help with regular expressions

2018-02-12 Thread Dennis Fisher
R 3.4.2
OS X

Colleagues

I would appreciate some help with regular expressions.

I have string that looks like:
" ITERATION  ,THETA1 ,THETA2
 ,THETA3 ,THETA4 ,THETA5 
,THETA6 ,THETA7 ,SIGMA(1,1) 
,SIGMA(2,1) ,SIGMA(2,2)”

In the entries that contain:
(X,Y)   # for example, SIGMA(1,1)
I would like to replace the comma with a period, e.g., SIGMA(1.1) but NOT the 
other commas

The end-result would be:
" ITERATION  ,THETA1 ,THETA2
 ,THETA3 ,THETA4 ,THETA5 
,THETA6 ,THETA7 ,SIGMA(1.1) 
,SIGMA(2.1) ,SIGMA(2.2)”

Can someone provide the regular expression code to accomplish this?
Thanks.

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com

__
R-help@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.


Re: [R] plotting the regression coefficients

2018-02-12 Thread greg holly
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 
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 
> 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.hho...@gmail.com]
> > Sent: Monday, February 12, 2018 8:52 AM
> > To: PIKAL Petr 
> > Cc: r-help mailing list 
> > 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  mailto:petr.pi...@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.hho...@gmail.com mak.hho...@gmail.com>]
> > Sent: Saturday, February 10, 2018 9:05 PM
> >
> > To: PIKAL Petr mailto:petr.pi...@precheza.cz>>
> > Cc: r-help mailing list  -h...@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.hho...@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  mailto:petr.pi...@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,
>

Re: [R] plotting the regression coefficients

2018-02-12 Thread Richard M. Heiberger
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  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.hho...@gmail.com]
> Sent: Monday, February 12, 2018 8:52 AM
> To: PIKAL Petr 
> Cc: r-help mailing list 
> 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 
> mailto:petr.pi...@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.hho...@gmail.com]
> Sent: Saturday, February 10, 2018 9:05 PM
>
> To: PIKAL Petr mailto:petr.pi...@precheza.cz>>
> Cc: r-help mailing list mailto:r-help@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 
> mailto:mak.hho...@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 
> mailto:petr.pi...@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.hho...@gmail.com]
> Sent: Thursday, February 8, 2018 9:23 AM
> To: PIKAL Petr mailto:petr.pi...@precheza.cz>>
> Cc: r-help mailing list mailto:r-help@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 
> mailto:petr.pi...@precheza.cz>> wrote:
> Hi
>
> Example, example, example - preferab

Re: [R] plotting the regression coefficients

2018-02-12 Thread PIKAL Petr
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.hho...@gmail.com]
Sent: Monday, February 12, 2018 8:52 AM
To: PIKAL Petr 
Cc: r-help mailing list 
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 
mailto:petr.pi...@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.hho...@gmail.com]
Sent: Saturday, February 10, 2018 9:05 PM

To: PIKAL Petr mailto:petr.pi...@precheza.cz>>
Cc: r-help mailing list mailto:r-help@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 
mailto:mak.hho...@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 
mailto:petr.pi...@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.hho...@gmail.com]
Sent: Thursday, February 8, 2018 9:23 AM
To: PIKAL Petr mailto:petr.pi...@precheza.cz>>
Cc: r-help mailing list mailto:r-help@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 
mailto:petr.pi...@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-boun...@r-project.org] On 
> Behalf Of greg holly
> Sent: Thursday, February 8, 2018 8:14 AM
> To: r-help mailing list mailto:r-help@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 y