Re: [R] ggplot 3-color gradient scales

2020-08-23 Thread Rui Barradas

Hello,

Note that the midpoint argument can make a big difference. In the code 
below try commenting out the line where the default is changed.



f <- function(x){
  (x - min(x))/(max(x) - min(x))
}

library(ggplot2)

df1 <- iris[3:5]
names(df1)[1:2] <- c("x", "y")
df1$z <- ave(df1$y, df1$Species, FUN = f)

ggplot(df1) +
  geom_point( aes(x, y, color = z) ) +
  scale_color_gradient2(low = "red",
mid = "yellow",
high = "blue",
midpoint = 0.5
)

Hope this helps,

Rui Barradas


Às 04:43 de 24/08/20, Jeff Newmiller escreveu:

Check out scale_colour_gradient2()

On August 23, 2020 8:12:06 PM PDT, April Ettington  
wrote:

Currently I am using these settings in ggplot to make a gradient from
red
to blue.

geom_point( aes(x, y, color=z) ) +
scale_colour_gradient(low = "red",high = "blue") +

z is a ratio, and currently I am able to identify which have high and
low
values, but I'd really like to be able to distinguish which are >1, <1,
or
close to 1 by color.  It would be great if I could set a middle color
in
this gradient (eg. green) that is set the the value of 1, even if that
is
not the exact midpoint between my highest and lowest values.  Is there
a
way to do this in R?

Thank you,
April

[[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.




__
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] ggplot 3-color gradient scales

2020-08-23 Thread Jeff Newmiller
Check out scale_colour_gradient2()

On August 23, 2020 8:12:06 PM PDT, April Ettington  
wrote:
>Currently I am using these settings in ggplot to make a gradient from
>red
>to blue.
>
>geom_point( aes(x, y, color=z) ) +
>scale_colour_gradient(low = "red",high = "blue") +
>
>z is a ratio, and currently I am able to identify which have high and
>low
>values, but I'd really like to be able to distinguish which are >1, <1,
>or
>close to 1 by color.  It would be great if I could set a middle color
>in
>this gradient (eg. green) that is set the the value of 1, even if that
>is
>not the exact midpoint between my highest and lowest values.  Is there
>a
>way to do this in R?
>
>Thank you,
>April
>
>   [[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] ggplot 3-color gradient scales

2020-08-23 Thread April Ettington
Currently I am using these settings in ggplot to make a gradient from red
to blue.

geom_point( aes(x, y, color=z) ) +
scale_colour_gradient(low = "red",high = "blue") +

z is a ratio, and currently I am able to identify which have high and low
values, but I'd really like to be able to distinguish which are >1, <1, or
close to 1 by color.  It would be great if I could set a middle color in
this gradient (eg. green) that is set the the value of 1, even if that is
not the exact midpoint between my highest and lowest values.  Is there a
way to do this in R?

Thank you,
April

[[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] plot.window: need finite 'ylim' values

2020-08-23 Thread Jim Lemon
Hi Mike,
This looks to me as though the error is not being generated by plot,
but by a method specific to the package, maybe something with a name
like plot.chart_Series, that is barfing on a vector of NA values.

Jim

On Mon, Aug 24, 2020 at 1:01 AM Mike  wrote:
>
> Hi Jim,
>
> on 21.08. you wrote:
>
> > Try this:
> >
> > plot (chart_Series (sample.xts[,1], subset=subset, TA=ta),
> >  type="n",ylim=c(minimum,maximum))
> >
> > where minimum and maximum are the extremes of the plot if there were
> > any valid values.
>
> I've set
> minimum <- 0
> maximum <- 1
>
> The error persists.
>
> But besides that, passing 'type="n"' to plot would only make sense
> when called once an I know there are only NAs to plot. Since I want to
> generate many charts in a loop I would have to check for plotable data
> first to decide if 'type="n"' should be passed.
>
> As a workaround for now I do something similar. I check if the range
> to be plotted is completely NA. If so I manipulate one of those
> observations (which can only be 0, 1 or NA) to an "illegal" value of
> 0.5.
>
> Mike
>
> __
> 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] plot.window: need finite 'ylim' values

2020-08-23 Thread David Winsemius
You are using a function whose help page says it is "highly experimental". In 
such cases it is probably better to contact the package maintainer with a 
feature request. The DESCRIPTION file says contact should be through one of 

http://www.quantmod.com 
https://github.com/joshuaulrich/quantmod



-- 
David.
> On Aug 20, 2020, at 10:55 AM, Mike  wrote:
> 
> Dear R users,
> 
> I have already asked this in r-sig-finance (not getting a solution)
> but it seems to be plot-related anyway.
> 
> I like to plot several financial charts to files with an identical
> layout according to "indicators" so the charts can be browsed
> quickly.
> 
> quantmod::chart_Series is a function to plot a financially-related
> chart in the upper part and zero or more indicators below. Normally
> these indicators would be assigned defined values at least in some
> part of the subset/window to be plotted, which is fine for plot. But
> if all observations are NA chart_Series throws
> 
> Error in plot.window(c(1, 31), c(NaN, NaN)) : need finite 'ylim' values
> 
> While this outcome for plot/plot.window may be intended for most
> applications it is undesirable here. Getting a blank subwindow here is
> intended if the indicator is completely NA (at least in the subset to
> be plotted).
> 
> This post
> https://stat.ethz.ch/pipermail/r-sig-finance/2020q3/015000.html
> suggests to generate the plot object with chart_Series and then to
> explicitly set x$Env$ylim[[4]] before plotting - without success.
> 
> Can I tell plot/plot.window to ignore such errors and simply generate
> an empty region instead?
> 
> Thanks
> Mike
> 
> 
> My minimal reproducible:
> 
> library(quantmod)
> 
> my_plot_function <- function () {
>  data (sample_matrix)
>  sample.xts <- as.xts (sample_matrix[1:50,'Close'], dateFormat="POSIXct")
>  sample.xts <- cbind (sample.xts, NA)
>  sample.xts[50,2] <- 0
>  colnames (sample.xts) <- c('Close', 'Indicator')
> 
>  # Indicator
>  ta <- list ("add_TA(sample.xts[,2])")
> 
>  # In the range to be plotted ta is completely NA 
>  subset <- '2007-01-10::2007-01-30'
> 
>  plot (chart_Series (sample.xts[,1], subset=subset, TA=ta))
> }
> 
> my_plot_function ()
> 
> __
> 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] plot.window: need finite 'ylim' values

2020-08-23 Thread Mike
Hi Jim,

on 21.08. you wrote:

> Try this:
> 
> plot (chart_Series (sample.xts[,1], subset=subset, TA=ta),
>  type="n",ylim=c(minimum,maximum))
> 
> where minimum and maximum are the extremes of the plot if there were
> any valid values.

I've set
minimum <- 0
maximum <- 1

The error persists.

But besides that, passing 'type="n"' to plot would only make sense
when called once an I know there are only NAs to plot. Since I want to
generate many charts in a loop I would have to check for plotable data
first to decide if 'type="n"' should be passed.

As a workaround for now I do something similar. I check if the range
to be plotted is completely NA. If so I manipulate one of those
observations (which can only be 0, 1 or NA) to an "illegal" value of
0.5.

Mike

__
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] Export R outputs to SAS dataset

2020-08-23 Thread Jomy Jose
 Hi Daniel

Thanks,please find the code and output

 #R libraries-
  library(tidyverse)
  library(MF)


MFSubj(lesion ~ group, calflung)
HLBoot(lesion ~ group,  calflung, compare = c("con", "vac"), b = 100,
  B = 100, alpha = 0.05, hpd = TRUE, bca = FALSE,
  return.boot = FALSE, trace.it = FALSE, seed = NULL)


1 bootstrap samples
95% confidence intervals
Comparing vac to con


Mitigated Fraction

observed median  lower  upper
Equal Tailed0.44 0.4464 0.1360 0.7024
Highest Density 0.44 0.4464 0.1456 0.7088


Hodges-Lehmann

observed   median lowerupper
Equal Tailed-0.07335 -0.07125 -0.170425 -0.01480
Highest Density -0.07335 -0.07125 -0.156350 -0.00975


Quartile Differences (quartiles of vac - quartiles of con)

 observedmedianlower upper
Q25 -0.041500 -0.041300 -0.10340 -0.000905
Q50 -0.112525 -0.75 -0.28115  0.019350
Q75 -0.168000 -0.170425 -0.38650  0.03


Quartiles of con
observed   median   lower   upper
Q25 0.054000 0.054000 0.01525 0.11275
Q50 0.139275 0.139275 0.06140 0.31000
Q75 0.315000 0.315000 0.17300 0.45250


Quartiles of vac
observed  median   lowerupper
Q25  0.01250 0.01250 0.00125 0.026000
Q50  0.02675 0.02675 0.01665 0.144575
Q75  0.14700 0.14700 0.02810 0.292000


Best
Jose

On Sun, Aug 23, 2020 at 2:44 AM Daniel Nordlund 
wrote:

> On 8/22/2020 9:05 AM, Rasmus Liland wrote:
> > On 2020-08-22 08:17 +0530, Jomy Jose wrote:
> > | Hi
> > | I was able to run R code via PROC IML
> > | in SAS,so is there any way to export
> > | the generated outputs to SAS datasets
> > | since the R outputs don't follow data
> > | frame structure.
> >
> > Dear Jomy,
> >
> > But perhaps you can take the outputs in
> > SAS and work on them inside from there?
> >
> > To export a data frame from R to SAS via
> > a file[1], you can use
> >
> >   foreign::write.foreign(..., package="SAS")
> >
> > But I have not tried it.
> >
> > I have used foreign::read.spss before,
> > hehe :-)
> >
> > I know R is also possible to call from
> > Julia, and the df appearing in Julia,
> > this sounds like it should be possible
> > SAS too[2], yes?
> >
> > Best,
> > Rasmus
> >
> > [1] https://www.statmethods.net/input/exportingdata.html
> > [2]
> https://documentation.sas.com/?docsetId=imlug=imlug_r_sect012.htm=15.1=en
> >
> > __
> > 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.
>
> Can you give a reproducible example of the R-code you are running and
> the R "output" you want to get back in SAS?  It is difficult from way
> over here to know if you are wanting numerical results like means or
> regression coefficients ... or if you just want printed output in your
> SAS log or listing.
>
> Dan
>
> --
> Daniel Nordlund
> Port Townsend, WA  USA
>
>

[[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] Error in optim with method L-BFGS-B when hessian is TRUE

2020-08-23 Thread Marc Girondot via R-help

Sorry... it is already stated in the help, at the hessian section:

hessian
Only if argument hessian is true. A symmetric matrix giving an estimate 
of the Hessian at the solution found. Note that this is the Hessian of 
the unconstrained problem even if the box constraints are active.


So no problem...

Marc

Le 23/08/2020 ?? 11:19, Marc Girondot via R-help a ??crit??:

Dear members,

I fought for several days against an error I was getting with optim in 
L-BFGS-B. The error was produced because some parameters were outside 
the limits defined by upper and lower.
After investigation, the error is not produced during the optimization 
itself but during the calculation of the Hessian matrix which does not 
take into account the upper and lower bounds.
It would be nice if this was stated in the optim help within the 
L-BFGS-B method section.


Marc Girondot

__
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] Error in optim with method L-BFGS-B when hessian is TRUE

2020-08-23 Thread Marc Girondot via R-help

Dear members,

I fought for several days against an error I was getting with optim in 
L-BFGS-B. The error was produced because some parameters were outside 
the limits defined by upper and lower.
After investigation, the error is not produced during the optimization 
itself but during the calculation of the Hessian matrix which does not 
take into account the upper and lower bounds.
It would be nice if this was stated in the optim help within the 
L-BFGS-B method section.


Marc Girondot

__
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.