Re: [R-es] Error: protect(): protection stack overflow

2023-05-30 Thread Javier Marcuzzi
Estimado Manuel Mendoza

Puede ser que a usted no le sea de utilidad, pero cuándo nombran genes y 
evalúan, yo siempre de acuerdo del libro Introducción a la Genética 
Cuantitativa, de Falconer. Digo esto porque la expresión que usted nombra puede 
ser por deriva genética y no por un efecto real del gen.

Un abrazo
Javier Rubén Marcuzzi



> El 29 may. 2023, a las 06:18, Manuel Mendoza  
> escribió:
> 
> Gracias Carlos e Isidro, finalmente utilicé el propio XgBoost para
> seleccionar las variables con las que hacer el RF. Había 47, de las casi
> 55.000, que mostraban una ganancia superior que el resto, así que hice el
> RF con esas sin problema. La idea original era aplicar RF para seleccionar
> las variables más importantes por su contribución a la predicción,
> utilizando meandecraseaccuracy, y es lo que hice, aunque partiendo de esas
> 47. Resultó que con tan solo 5 genes puedo predecir la malignidad de
> tumores (neurofibromas) con una sensibilidad del 98%. Un hallazgo
> interesante.
> Gracias de nuevo,
> Manuel
> 
> El dom, 28 may 2023 a las 21:58, Carlos Ortega ()
> escribió:
> 
>> Hola Manuel,
>> 
>> "ranger" paraleliza de forma automática, usando todos los cores que
>> tienes. Está bastante optimizado...
>> 
>> El que se quede sin memoria, puede tener que ver, tanto por el número de
>> columnas que comentas, como que alguna de tus variables (o varias) si es
>> categórica y tiene múltiples niveles esas 54973 columnas pueden aumentar
>> mucho ("ranger" hace un one-hot interno).
>> 
>> Y si el problema son las columnas. ¿Tienes que usar todas las columnas?.
>> Puedes plantearte alguna alternativa para seleccionar las variables
>> importantes. El paquete "Boruta" es uno de ellos, pero también puedes hacer
>> diferentes modelos en modo "boostrap" seleccionado diferentes columnas para
>> ver con cuáles quedarte al final.
>> 
>> Y otra alternativa cuando tienes problemas de memoria, es usar H2O
>> Gestiona muy bien la memoria.
>> 
>> Gracias,
>> Carlos.
>> 
>> El dom, 28 may 2023 a las 13:29, Manuel Mendoza (<
>> mmend...@fulbrightmail.org>) escribió:
>> 
>>> Muy buenas, estoy aplicando random forest a una df de 256 filas y 54973
>>> columnas y me quedo sin memoria. He probado con randomForest y con ranger,
>>> y con los dos pasa. ¿Tenéis alguna solución para esto (que no sea
>>> comprarse
>>> un ordenador más potente:-) ?. Pude aplicar XgBoost, incluso cerca de 2000
>>> veces  (unas 16 horas), para optimizar los hiperparámetros con una rejilla
>>> de búsqueda, pero XgBoost utiliza varios núcleos a la vez. No sé si hay
>>> forma de hacer que randomForest o ranger utilicen más núcleos. Cualquier
>>> otra solución sería buena, claro.
>>> Gracias,
>>> Manuel
>>> 
>>>[[alternative HTML version deleted]]
>>> 
>>> ___
>>> R-help-es mailing list
>>> R-help-es@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>> 
>> 
>> 
>> --
>> Saludos,
>> Carlos Ortega
>> www.qualityexcellence.es
>> 
> 
>   [[alternative HTML version deleted]]
> 
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] lattice xyplot: how to change the y-axis labels size using yscale.components.subticks on the right side and how to adapt the ticks number

2023-05-30 Thread Deepayan Sarkar
Thanks for the reproducible example. Could you explain what you want
in a bit more detail? Does the following do more or less what you
want, except that the labels are on the left instead of right?

gr <-
xyplot(value ~ tindexTOP | sensor
 , data = df_rhelp
 , ylab = " "
 , xlab = list("Time (s)", font=9)
 , main = "test yscale.components with axis"
 , subset = sensor %in% paste0("sensor",1:8)
 , layout = c(1,8)
 , between = list(y = 0.5),
 , scales = list(y = list(relation = "free", cex = 0.3, rot = 0)
   , x = list(relation = "same", axs = "i",
  rot = 45, cex = 0.3))
 , type = c("l","g")
 , yscale.components = my_yscale.components.subticks
   ## , xscale.components = xscale.components.subticks
 , strip = F
 , strip.left = strip.custom(
   par.strip.text = list(font=3, cex = 0.5,col="red",lines=3)
   )
 , par.strip.text = list(font=3, cex = 0.5,col="red",lines=2)
 , par.settings = list(plot.line  = list(col = "black")
 , strip.background=list(col="transparent")
 , layout.widths = list(axis.key.padding = 5)
   ))

If you want the same labels on the right as well, you will just need
to uncomment the line

   ans$right <- TRUE

in your my_yscale.components.subticks function.

-Deepayan

On Tue, May 30, 2023 at 12:39 AM Laurent Rhelp  wrote:
>
> Dear R-Help-list,
>
> I want to display many sensors on the same page so I have to adapt
> the size of the y-axis labels and I woul like to adapt the number of
> ticks according to the sensor. I use the yscale.components argument with
> the function yscale.components.subticks: see the code below.
>
> In order to change the size labels on the right I tried to add the line
> ans$left$labels$cex <- 0.3 in yscale.components.subticks but it doesn't
> work. I try to put cex = 0.3 in the scale argument for the y list but it
> doesn't work too.
>
> And since the numeric ranges of sensors are different I would like to
> adapt the ticks number for every sensor. But I didn't undestand how to
> pass the value of the n argument at the yscale.components function and
> how I can use this function according to the current panel.
>
> Thank you
>
> Best regards
>
> Laurent
>
>
> o<-->o
>
> The data:
>
> df_rhelp <- structure(list(tindexTOP = c(4.76837158203125e-07,
> 4.76837158203125e-07,
> 4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
> 4.76837158203125e-07, 4.76837158203125e-07, 4.76837158203125e-07,
> 4.76837158203125e-07, 2.86102294921875e-06, 2.86102294921875e-06,
> 2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
> 2.86102294921875e-06, 2.86102294921875e-06, 2.86102294921875e-06,
> 2.86102294921875e-06, 5.48362731933594e-06, 5.48362731933594e-06,
> 5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
> 5.48362731933594e-06, 5.48362731933594e-06, 5.48362731933594e-06,
> 5.48362731933594e-06, 7.86781311035156e-06, 7.86781311035156e-06,
> 7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
> 7.86781311035156e-06, 7.86781311035156e-06, 7.86781311035156e-06,
> 7.86781311035156e-06, 1.04904174804688e-05, 1.04904174804688e-05,
> 1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
> 1.04904174804688e-05, 1.04904174804688e-05, 1.04904174804688e-05,
> 1.04904174804688e-05, 1.28746032714844e-05, 1.28746032714844e-05,
> 1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
> 1.28746032714844e-05, 1.28746032714844e-05, 1.28746032714844e-05,
> 1.28746032714844e-05, 1.54972076416016e-05, 1.54972076416016e-05,
> 1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
> 1.54972076416016e-05, 1.54972076416016e-05, 1.54972076416016e-05,
> 1.54972076416016e-05, 1.78813934326172e-05, 1.78813934326172e-05,
> 1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
> 1.78813934326172e-05, 1.78813934326172e-05, 1.78813934326172e-05,
> 1.78813934326172e-05, 2.05039978027344e-05, 2.05039978027344e-05,
> 2.05039978027344e-05, 2.05039978027344e-05, 2.05039978027344e-05,
> 2.05039978027344e-05, 2.05039978027344e-05, 2.05039978027344e-05,
> 2.05039978027344e-05, 2.288818359375e-05, 2.288818359375e-05,
> 2.288818359375e-05, 2.288818359375e-05, 2.288818359375e-05,
> 2.288818359375e-05,
> 2.288818359375e-05, 2.288818359375e-05, 2.288818359375e-05,
> 2.55107879638672e-05,
> 2.55107879638672e-05, 2.55107879638672e-05, 2.55107879638672e-05,
> 2.55107879638672e-05, 2.55107879638672e-05, 2.55107879638672e-05,
> 2.55107879638672e-05, 2.55107879638672e-05, 2.78949737548828e-05
> ), sensor = structure(c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L,
> 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L,
> 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 

[R-es] Trabajar con variables JSON

2023-05-30 Thread Jose Miguel Contreras
Hola a todos

Tengo una variable ‘medios', sacada de un JSON con la siguiente forma:

{'A': 2406, 'A1': 'Casa', 'media': [{'id': 1021, 'id_type': 7, 'type': None, 
'url': 'https://www.aaa1.com', 'from_date': 12}, {'id': 1036, 'id_type': 3, 
'type': None, 'url': 'https://bbb1.com', 'from_date': 12}, {'id': 1037, 
'id_type': 6, 'type': None, 'url': 'https://ccc1.com', 'from_date': 12}]}
{'B': 2407, 'A1': 'Casa', 'media': [{'id': 1022, 'id_type': 7, 'type': None, 
'url': 'https://www.aaa2.com', 'from_date': 13}, {'id': 1036, 'id_type': 3, 
'type': None, 'url': 'https://bbb2.com', 'from_date': 13}, {'id': 1037, 
'id_type': 6, 'type': None, 'url': 'https://ccc2.com', 'from_date': 13}]}
…..


La variable se carga como “character”.

La duda es esta, necesitaría extraer de cada fila las tres ‘url’ y meterlas en 
tres columnas distintas. Primero las convierto en JSON para trabajar con 
jsonlite, con toJSON, y luego utilizo 
data <- jsonlite::fromJSON(json_str) para intentar entrar en ella  con 
media_list <- data$medios, pero siempre me da el "error $ operator is invalid 
for atomic vectors”

Me podríais ayudar

Gracias

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Error: protect(): protection stack overflow

2023-05-30 Thread Juan Abasolo
Qué lindo participar desde la ventana de tu descubrimiento.

Te deseo que tengás un buen camino llevándolo adelante, por el bien de
tantos.

Hau idatzi du Manuel Mendoza (mmend...@fulbrightmail.org) erabiltzaileak
(2023 mai. 29(a), al. (11:19)):

> Gracias Carlos e Isidro, finalmente utilicé el propio XgBoost para
> seleccionar las variables con las que hacer el RF. Había 47, de las casi
> 55.000, que mostraban una ganancia superior que el resto, así que hice el
> RF con esas sin problema. La idea original era aplicar RF para seleccionar
> las variables más importantes por su contribución a la predicción,
> utilizando meandecraseaccuracy, y es lo que hice, aunque partiendo de esas
> 47. Resultó que con tan solo 5 genes puedo predecir la malignidad de
> tumores (neurofibromas) con una sensibilidad del 98%. Un hallazgo
> interesante.
> Gracias de nuevo,
> Manuel
>
> El dom, 28 may 2023 a las 21:58, Carlos Ortega ( >)
> escribió:
>
> > Hola Manuel,
> >
> > "ranger" paraleliza de forma automática, usando todos los cores que
> > tienes. Está bastante optimizado...
> >
> > El que se quede sin memoria, puede tener que ver, tanto por el número de
> > columnas que comentas, como que alguna de tus variables (o varias) si es
> > categórica y tiene múltiples niveles esas 54973 columnas pueden aumentar
> > mucho ("ranger" hace un one-hot interno).
> >
> > Y si el problema son las columnas. ¿Tienes que usar todas las columnas?.
> > Puedes plantearte alguna alternativa para seleccionar las variables
> > importantes. El paquete "Boruta" es uno de ellos, pero también puedes
> hacer
> > diferentes modelos en modo "boostrap" seleccionado diferentes columnas
> para
> > ver con cuáles quedarte al final.
> >
> > Y otra alternativa cuando tienes problemas de memoria, es usar H2O
> > Gestiona muy bien la memoria.
> >
> > Gracias,
> > Carlos.
> >
> > El dom, 28 may 2023 a las 13:29, Manuel Mendoza (<
> > mmend...@fulbrightmail.org>) escribió:
> >
> >> Muy buenas, estoy aplicando random forest a una df de 256 filas y 54973
> >> columnas y me quedo sin memoria. He probado con randomForest y con
> ranger,
> >> y con los dos pasa. ¿Tenéis alguna solución para esto (que no sea
> >> comprarse
> >> un ordenador más potente:-) ?. Pude aplicar XgBoost, incluso cerca de
> 2000
> >> veces  (unas 16 horas), para optimizar los hiperparámetros con una
> rejilla
> >> de búsqueda, pero XgBoost utiliza varios núcleos a la vez. No sé si hay
> >> forma de hacer que randomForest o ranger utilicen más núcleos. Cualquier
> >> otra solución sería buena, claro.
> >> Gracias,
> >> Manuel
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> ___
> >> R-help-es mailing list
> >> R-help-es@r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-help-es
> >>
> >
> >
> > --
> > Saludos,
> > Carlos Ortega
> > www.qualityexcellence.es
> >
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>


-- 
Juan Abasolo, PhD

Hizkuntzaren eta Literaturaren Didaktika Saila | EUDIA ikerketa taldea
Bilboko Hezkuntza Fakultatea
Euskal Herriko Unibertsitatea UPV/EHU

Sarriena auzoa z/g 48940 - Leioa (Bizkaia)

T   : (+34) 94 601 7567
Telegram: @JuanAbasolo
Skype   : abasolo72
Bloga   : juanabasolo.netlify.com

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] plot level, velocity, acceleration with one x axis

2023-05-30 Thread Eric Berger
What if you just precede these commands as follows:

par(mfrow=c(3,1))
plot(DAX.[, 1], log='y', ylab='DAX')
plot(DAX.[, 2], ylab='vel (%)')
plot(DAX.[, 3], ylab='accel (%)')

On Tue, May 30, 2023 at 5:45 PM Spencer Graves
 wrote:
>
>
>
> On 5/30/23 8:48 AM, Eric Berger wrote:
> > I am a bit confused as to what you are trying to achieve - and  even
> > if I could guess it is not clear what the interpretation would be.
> >> head(DAX)
> > 1628.75 1613.63 1606.51 1621.04 1618.16 1610.61
> >
> > Including the leading NA's, what would be the 6 leading terms of the 3
> > series that you want to plot,
> > and what would be the Y labels that you want to appear at those levels
> > (assuming that there was a
> > Y label for each of them - just to understand the units you are talking 
> > about)
>
>
> DAX <- EuStockMarkets[, 'DAX']
> DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX
> colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
> head(DAX.)
>
>
>   DAX exhibits growth that is roughly exponential, so I want to plot 
> it
> on a log scale:
>
>
> plot(DAX.[, 1], log='y', ylab='DAX')
> plot(DAX.[, 2], ylab='vel (%)')
> plot(DAX.[, 3], ylab='accel (%)')
>
>
>   This is what I want as three panels of a single plot.
>
>
>   I think I could get it by modifying the code for plot.ts so it
> accepted ylab as a vector, etc., as I previously mentioned.
>
>
>   What do you think?
>   Thanks,
>   Spencer Graves
> >
> >
> > On Tue, May 30, 2023 at 4:06 PM Spencer Graves
> >  wrote:
> >>
> >>
> >>
> >> On 5/30/23 6:16 AM, Eric Berger wrote:
> >>> My code assumes that DAX is a ts object, as in your original post.
> >>>
> >>> On Tue, May 30, 2023 at 2:06 PM Eric Berger  wrote:
> 
>  Untested but why not
> 
>  a <- cbind(log(DAX), exp(diff(log(DAX))), exp(diff(diff(log(DAX)
>  colnames(a) <- c("logDAX", "vel", "accel")
>  plot(a)
> >>
> >>
> >>Progress, but we're not there yet.
> >>
> >>
> >> a <- cbind(DAX, exp(diff(log(DAX))), exp(diff(diff(log(DAX)
> >> colnames(a) <- c("logDAX", "vel", "accel")
> >> plot(a)
> >> plot(a, axes=FALSE, log='y')
> >> axis(1)
> >> axis(2)
> >>
> >>
> >>How do I get each y axis labeled in its original units?  I can 
> >> use
> >> pretty to get where I want tick marks, but I don't know where to place
> >> them "at" in calling axis(2, at= ___)?
> >>
> >>
> >> (axlb1 <- pretty(range(a[, 1])))
> >> (axlb2 <- pretty(range(log(a[, 2]), na.rm=TRUE)))
> >> (axlb3 <- pretty(range(log(a[, 3]), na.rm=TRUE)))
> >>
> >>
> >>This suggests I write my own modification of plot.ts that 
> >> accepts log
> >> as a character vector of length = ncol of the ts being plotted and
> >> returns invisibly a list with the default "at" and "label" arguments
> >> required to produce the default labeling.  Then a user who wants a log
> >> scale for some but not all variables can get that easily and can further
> >> modify any of those scales further if they don't like the default.
> >>
> >>
> >>???
> >>Thanks very much.
> >>Spencer Graves
> 
> 
>  On Tue, May 30, 2023 at 1:46 PM Spencer Graves
>   wrote:
> >
> >
> >
> > On 5/29/23 2:37 AM, Eric Berger wrote:
> >> How about this:
> >>
> >> a <- cbind(AirPassengers, diff(log(AirPassengers)),
> >> diff(diff(log(AirPassengers
> >> colnames(a)[2:3] <- c("percent increase", "acceleration")
> >> plot(a, xlab="year", main="AirPassengers")
> >
> >
> > My real problem is more difficult:  I'm analyzing CO2 data 
> > from Our
> > World in Data (https://ourworldindata.org/co2-emissions), and I need to
> > plot the CO2 data on a log scale but velocity and acceleration on linear
> > scales.  The following is comparable:
> >
> >
> > str(DAX <- EuStockMarkets[, 'DAX'])
> > str(DAX. <- cbind(DAX, diff(log(DAX)),
> >  diff(diff(log(DAX)
> > colnames(DAX.)[2:3] <- c('vel', 'accel')
> > plot(DAX.)
> >
> >
> > I want the first of the three panels to plot on the log 
> > scale, but
> > the other two on linear scales.  The obvious attempt does not work:
> >
> >
> > plot(DAX., log=c('y', '', ''))
> > #Error in length(log) && log != "" :
> > #  'length = 3' in coercion to 'logical(1)'
> >
> >
> > Trying to construct my own axes isn't easy, either:
> >
> >
> > str(logDAX <- cbind(log(DAX), diff(log(DAX)),
> >  diff(diff(log(DAX)
> > colnames(logDAX) <- c('logDAX', 'vel', 'accel')
> > plot(logDAX, axes=FALSE)
> > axis(1)
> > axis(2)
> >
> >
> > I'm thinking of creating my own copy of "plot.ts", and 
> > changing it so
> > it accepts the "log" argument as a vector of length equal to ncol of the
> > ts object to be plotted AND returning an 

Re: [R] plot level, velocity, acceleration with one x axis

2023-05-30 Thread Spencer Graves




On 5/30/23 8:48 AM, Eric Berger wrote:

I am a bit confused as to what you are trying to achieve - and  even
if I could guess it is not clear what the interpretation would be.

head(DAX)

1628.75 1613.63 1606.51 1621.04 1618.16 1610.61

Including the leading NA's, what would be the 6 leading terms of the 3
series that you want to plot,
and what would be the Y labels that you want to appear at those levels
(assuming that there was a
Y label for each of them - just to understand the units you are talking about)



DAX <- EuStockMarkets[, 'DAX']
DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX
colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
head(DAX.)


	  DAX exhibits growth that is roughly exponential, so I want to plot it 
on a log scale:



plot(DAX.[, 1], log='y', ylab='DAX')
plot(DAX.[, 2], ylab='vel (%)')
plot(DAX.[, 3], ylab='accel (%)')


  This is what I want as three panels of a single plot.


	  I think I could get it by modifying the code for plot.ts so it 
accepted ylab as a vector, etc., as I previously mentioned.



  What do you think?
  Thanks,
  Spencer Graves



On Tue, May 30, 2023 at 4:06 PM Spencer Graves
 wrote:




On 5/30/23 6:16 AM, Eric Berger wrote:

My code assumes that DAX is a ts object, as in your original post.

On Tue, May 30, 2023 at 2:06 PM Eric Berger  wrote:


Untested but why not

a <- cbind(log(DAX), exp(diff(log(DAX))), exp(diff(diff(log(DAX)
colnames(a) <- c("logDAX", "vel", "accel")
plot(a)



   Progress, but we're not there yet.


a <- cbind(DAX, exp(diff(log(DAX))), exp(diff(diff(log(DAX)
colnames(a) <- c("logDAX", "vel", "accel")
plot(a)
plot(a, axes=FALSE, log='y')
axis(1)
axis(2)


   How do I get each y axis labeled in its original units?  I can use
pretty to get where I want tick marks, but I don't know where to place
them "at" in calling axis(2, at= ___)?


(axlb1 <- pretty(range(a[, 1])))
(axlb2 <- pretty(range(log(a[, 2]), na.rm=TRUE)))
(axlb3 <- pretty(range(log(a[, 3]), na.rm=TRUE)))


   This suggests I write my own modification of plot.ts that accepts log
as a character vector of length = ncol of the ts being plotted and
returns invisibly a list with the default "at" and "label" arguments
required to produce the default labeling.  Then a user who wants a log
scale for some but not all variables can get that easily and can further
modify any of those scales further if they don't like the default.


   ???
   Thanks very much.
   Spencer Graves



On Tue, May 30, 2023 at 1:46 PM Spencer Graves
 wrote:




On 5/29/23 2:37 AM, Eric Berger wrote:

How about this:

a <- cbind(AirPassengers, diff(log(AirPassengers)),
diff(diff(log(AirPassengers
colnames(a)[2:3] <- c("percent increase", "acceleration")
plot(a, xlab="year", main="AirPassengers")



My real problem is more difficult:  I'm analyzing CO2 data from Our
World in Data (https://ourworldindata.org/co2-emissions), and I need to
plot the CO2 data on a log scale but velocity and acceleration on linear
scales.  The following is comparable:


str(DAX <- EuStockMarkets[, 'DAX'])
str(DAX. <- cbind(DAX, diff(log(DAX)),
 diff(diff(log(DAX)
colnames(DAX.)[2:3] <- c('vel', 'accel')
plot(DAX.)


I want the first of the three panels to plot on the log scale, but
the other two on linear scales.  The obvious attempt does not work:


plot(DAX., log=c('y', '', ''))
#Error in length(log) && log != "" :
#  'length = 3' in coercion to 'logical(1)'


Trying to construct my own axes isn't easy, either:


str(logDAX <- cbind(log(DAX), diff(log(DAX)),
 diff(diff(log(DAX)
colnames(logDAX) <- c('logDAX', 'vel', 'accel')
plot(logDAX, axes=FALSE)
axis(1)
axis(2)


I'm thinking of creating my own copy of "plot.ts", and changing it 
so
it accepts the "log" argument as a vector of length equal to ncol of the
ts object to be plotted AND returning an object that would allow a user
to call "axis" ncol times.


Suggestions?


Thanks,
Spencer Graves



HTH,
Eric


On Mon, May 29, 2023 at 7:57 AM Spencer Graves
 wrote:


Hello, All:


 I want to plot level, velocity, and acceleration in three panels 
with
only one x axis.  The code below does this using "layout".  However, I
want the three plot areas to be of equal size, and this won't do that:
If I stretch the plot vertically, the relative sizes of the three panels
changes.  There's probably a way to do this with ggplot2, but I have yet
to find it.


 Suggestions?
 Thanks,
 Spencer Graves


str(AirTime <- as.numeric(time(AirPassengers)))
str(AP <- as.numeric(AirPassengers))

def.par <- par(no.readonly = TRUE) # save default, for resetting...
(mat3x1 <- matrix(1:3, 3))
plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
layout.show(plot3x1)

par(mar=c(0, 4.1, 4.1, 2.1))
plot(AirTime, AP, log='y', type='l', 

Re: [R] helps in closing a shiny session

2023-05-30 Thread Bert Gunter
Shiny is a product created and supported by Posit.co, formerly known as
Rstudio. They have their own support forum here 
, which is likely a better place to post such queries.

Cheers,
Bert


On Tue, May 30, 2023 at 6:58 AM Cleber Borges via R-help <
r-help@r-project.org> wrote:

> Hello everybody
>
> I tried closing a shiny session with the call: session$close() and then
> I found that it didn't do what I thought it would.
>
> The result of calling: session$isClosed() is still FALSE.
>
> Does anyone have any tips on how to close the shiny session using a button?
>
> Thanks in advance for any help
>
> yours sincerely.,
>
> Cleber Borges
>
> --- CODE
>
> ui <- fluidPage( actionButton( "disconnect", "disconnect" ) )
>
> server <- function( input, output, session ) {
>  observeEvent( input$disconnect, {
>  session$close()
>  res <- session$isClosed()
>  print( paste0( "result of function isClosed() is: ", res ) )
>  })
> }
>
> shinyApp( ui, server )
>
> [[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.
>

[[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] helps in closing a shiny session

2023-05-30 Thread Cleber Borges via R-help
Hello everybody

I tried closing a shiny session with the call: session$close() and then 
I found that it didn't do what I thought it would.

The result of calling: session$isClosed() is still FALSE.

Does anyone have any tips on how to close the shiny session using a button?

Thanks in advance for any help

yours sincerely.,

Cleber Borges

--- CODE

ui <- fluidPage( actionButton( "disconnect", "disconnect" ) )

server <- function( input, output, session ) {
     observeEvent( input$disconnect, {
     session$close()
     res <- session$isClosed()
     print( paste0( "result of function isClosed() is: ", res ) )
     })
}

shinyApp( ui, server )

[[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 level, velocity, acceleration with one x axis

2023-05-30 Thread Eric Berger
I am a bit confused as to what you are trying to achieve - and  even
if I could guess it is not clear what the interpretation would be.
> head(DAX)
1628.75 1613.63 1606.51 1621.04 1618.16 1610.61

Including the leading NA's, what would be the 6 leading terms of the 3
series that you want to plot,
and what would be the Y labels that you want to appear at those levels
(assuming that there was a
Y label for each of them - just to understand the units you are talking about)


On Tue, May 30, 2023 at 4:06 PM Spencer Graves
 wrote:
>
>
>
> On 5/30/23 6:16 AM, Eric Berger wrote:
> > My code assumes that DAX is a ts object, as in your original post.
> >
> > On Tue, May 30, 2023 at 2:06 PM Eric Berger  wrote:
> >>
> >> Untested but why not
> >>
> >> a <- cbind(log(DAX), exp(diff(log(DAX))), exp(diff(diff(log(DAX)
> >> colnames(a) <- c("logDAX", "vel", "accel")
> >> plot(a)
>
>
>   Progress, but we're not there yet.
>
>
> a <- cbind(DAX, exp(diff(log(DAX))), exp(diff(diff(log(DAX)
> colnames(a) <- c("logDAX", "vel", "accel")
> plot(a)
> plot(a, axes=FALSE, log='y')
> axis(1)
> axis(2)
>
>
>   How do I get each y axis labeled in its original units?  I can use
> pretty to get where I want tick marks, but I don't know where to place
> them "at" in calling axis(2, at= ___)?
>
>
> (axlb1 <- pretty(range(a[, 1])))
> (axlb2 <- pretty(range(log(a[, 2]), na.rm=TRUE)))
> (axlb3 <- pretty(range(log(a[, 3]), na.rm=TRUE)))
>
>
>   This suggests I write my own modification of plot.ts that accepts 
> log
> as a character vector of length = ncol of the ts being plotted and
> returns invisibly a list with the default "at" and "label" arguments
> required to produce the default labeling.  Then a user who wants a log
> scale for some but not all variables can get that easily and can further
> modify any of those scales further if they don't like the default.
>
>
>   ???
>   Thanks very much.
>   Spencer Graves
> >>
> >>
> >> On Tue, May 30, 2023 at 1:46 PM Spencer Graves
> >>  wrote:
> >>>
> >>>
> >>>
> >>> On 5/29/23 2:37 AM, Eric Berger wrote:
>  How about this:
> 
>  a <- cbind(AirPassengers, diff(log(AirPassengers)),
>  diff(diff(log(AirPassengers
>  colnames(a)[2:3] <- c("percent increase", "acceleration")
>  plot(a, xlab="year", main="AirPassengers")
> >>>
> >>>
> >>>My real problem is more difficult:  I'm analyzing CO2 data 
> >>> from Our
> >>> World in Data (https://ourworldindata.org/co2-emissions), and I need to
> >>> plot the CO2 data on a log scale but velocity and acceleration on linear
> >>> scales.  The following is comparable:
> >>>
> >>>
> >>> str(DAX <- EuStockMarkets[, 'DAX'])
> >>> str(DAX. <- cbind(DAX, diff(log(DAX)),
> >>> diff(diff(log(DAX)
> >>> colnames(DAX.)[2:3] <- c('vel', 'accel')
> >>> plot(DAX.)
> >>>
> >>>
> >>>I want the first of the three panels to plot on the log scale, 
> >>> but
> >>> the other two on linear scales.  The obvious attempt does not work:
> >>>
> >>>
> >>> plot(DAX., log=c('y', '', ''))
> >>> #Error in length(log) && log != "" :
> >>> #  'length = 3' in coercion to 'logical(1)'
> >>>
> >>>
> >>>Trying to construct my own axes isn't easy, either:
> >>>
> >>>
> >>> str(logDAX <- cbind(log(DAX), diff(log(DAX)),
> >>> diff(diff(log(DAX)
> >>> colnames(logDAX) <- c('logDAX', 'vel', 'accel')
> >>> plot(logDAX, axes=FALSE)
> >>> axis(1)
> >>> axis(2)
> >>>
> >>>
> >>>I'm thinking of creating my own copy of "plot.ts", and 
> >>> changing it so
> >>> it accepts the "log" argument as a vector of length equal to ncol of the
> >>> ts object to be plotted AND returning an object that would allow a user
> >>> to call "axis" ncol times.
> >>>
> >>>
> >>>Suggestions?
> >>>
> >>>
> >>>Thanks,
> >>>Spencer Graves
> >>>
> 
>  HTH,
>  Eric
> 
> 
>  On Mon, May 29, 2023 at 7:57 AM Spencer Graves
>   wrote:
> >
> > Hello, All:
> >
> >
> > I want to plot level, velocity, and acceleration in three 
> > panels with
> > only one x axis.  The code below does this using "layout".  However, I
> > want the three plot areas to be of equal size, and this won't do that:
> > If I stretch the plot vertically, the relative sizes of the three panels
> > changes.  There's probably a way to do this with ggplot2, but I have yet
> > to find it.
> >
> >
> > Suggestions?
> > Thanks,
> > Spencer Graves
> >
> >
> > str(AirTime <- as.numeric(time(AirPassengers)))
> > str(AP <- as.numeric(AirPassengers))
> >
> > def.par <- par(no.readonly = TRUE) # save default, for resetting...
> > (mat3x1 <- matrix(1:3, 3))
> > plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
> > layout.show(plot3x1)
> >
> > par(mar=c(0, 4.1, 4.1, 2.1))
> > 

Re: [R] plot level, velocity, acceleration with one x axis

2023-05-30 Thread Spencer Graves




On 5/30/23 6:16 AM, Eric Berger wrote:

My code assumes that DAX is a ts object, as in your original post.

On Tue, May 30, 2023 at 2:06 PM Eric Berger  wrote:


Untested but why not

a <- cbind(log(DAX), exp(diff(log(DAX))), exp(diff(diff(log(DAX)
colnames(a) <- c("logDAX", "vel", "accel")
plot(a)



  Progress, but we're not there yet.


a <- cbind(DAX, exp(diff(log(DAX))), exp(diff(diff(log(DAX)
colnames(a) <- c("logDAX", "vel", "accel")
plot(a)
plot(a, axes=FALSE, log='y')
axis(1)
axis(2)


	  How do I get each y axis labeled in its original units?  I can use 
pretty to get where I want tick marks, but I don't know where to place 
them "at" in calling axis(2, at= ___)?



(axlb1 <- pretty(range(a[, 1])))
(axlb2 <- pretty(range(log(a[, 2]), na.rm=TRUE)))
(axlb3 <- pretty(range(log(a[, 3]), na.rm=TRUE)))


	  This suggests I write my own modification of plot.ts that accepts log 
as a character vector of length = ncol of the ts being plotted and 
returns invisibly a list with the default "at" and "label" arguments 
required to produce the default labeling.  Then a user who wants a log 
scale for some but not all variables can get that easily and can further 
modify any of those scales further if they don't like the default.



  ???
  Thanks very much.
  Spencer Graves



On Tue, May 30, 2023 at 1:46 PM Spencer Graves
 wrote:




On 5/29/23 2:37 AM, Eric Berger wrote:

How about this:

a <- cbind(AirPassengers, diff(log(AirPassengers)),
diff(diff(log(AirPassengers
colnames(a)[2:3] <- c("percent increase", "acceleration")
plot(a, xlab="year", main="AirPassengers")



   My real problem is more difficult:  I'm analyzing CO2 data from Our
World in Data (https://ourworldindata.org/co2-emissions), and I need to
plot the CO2 data on a log scale but velocity and acceleration on linear
scales.  The following is comparable:


str(DAX <- EuStockMarkets[, 'DAX'])
str(DAX. <- cbind(DAX, diff(log(DAX)),
diff(diff(log(DAX)
colnames(DAX.)[2:3] <- c('vel', 'accel')
plot(DAX.)


   I want the first of the three panels to plot on the log scale, but
the other two on linear scales.  The obvious attempt does not work:


plot(DAX., log=c('y', '', ''))
#Error in length(log) && log != "" :
#  'length = 3' in coercion to 'logical(1)'


   Trying to construct my own axes isn't easy, either:


str(logDAX <- cbind(log(DAX), diff(log(DAX)),
diff(diff(log(DAX)
colnames(logDAX) <- c('logDAX', 'vel', 'accel')
plot(logDAX, axes=FALSE)
axis(1)
axis(2)


   I'm thinking of creating my own copy of "plot.ts", and changing it so
it accepts the "log" argument as a vector of length equal to ncol of the
ts object to be plotted AND returning an object that would allow a user
to call "axis" ncol times.


   Suggestions?


   Thanks,
   Spencer Graves



HTH,
Eric


On Mon, May 29, 2023 at 7:57 AM Spencer Graves
 wrote:


Hello, All:


I want to plot level, velocity, and acceleration in three panels 
with
only one x axis.  The code below does this using "layout".  However, I
want the three plot areas to be of equal size, and this won't do that:
If I stretch the plot vertically, the relative sizes of the three panels
changes.  There's probably a way to do this with ggplot2, but I have yet
to find it.


Suggestions?
Thanks,
Spencer Graves


str(AirTime <- as.numeric(time(AirPassengers)))
str(AP <- as.numeric(AirPassengers))

def.par <- par(no.readonly = TRUE) # save default, for resetting...
(mat3x1 <- matrix(1:3, 3))
plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
layout.show(plot3x1)

par(mar=c(0, 4.1, 4.1, 2.1))
plot(AirTime, AP, log='y', type='l', axes=FALSE,
main='AirPassengers', ylab='AirPassengers')
box(col='grey')
axis(2, las=1)

par(mar=c(0, 4.1, 0, 2.1))
vAP <- diff(log(AP))
plot(tail(AirTime, -1), vAP, type='l',
ylab='percent increase', axes=FALSE)
box(col='grey')
axis(2, las=1)

par(mar=c(5.1, 4.1, 0, 2.1))
plot(tail(AirTime, -2), diff(vAP), type='l',
ylab='acceleration', xlab='year',
las=1)
box(col='grey')

par(def.par)

__
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 level, velocity, acceleration with one x axis

2023-05-30 Thread Eric Berger
My code assumes that DAX is a ts object, as in your original post.

On Tue, May 30, 2023 at 2:06 PM Eric Berger  wrote:
>
> Untested but why not
>
> a <- cbind(log(DAX), exp(diff(log(DAX))), exp(diff(diff(log(DAX)
> colnames(a) <- c("logDAX", "vel", "accel")
> plot(a)
>
>
> On Tue, May 30, 2023 at 1:46 PM Spencer Graves
>  wrote:
> >
> >
> >
> > On 5/29/23 2:37 AM, Eric Berger wrote:
> > > How about this:
> > >
> > > a <- cbind(AirPassengers, diff(log(AirPassengers)),
> > > diff(diff(log(AirPassengers
> > > colnames(a)[2:3] <- c("percent increase", "acceleration")
> > > plot(a, xlab="year", main="AirPassengers")
> >
> >
> >   My real problem is more difficult:  I'm analyzing CO2 data from 
> > Our
> > World in Data (https://ourworldindata.org/co2-emissions), and I need to
> > plot the CO2 data on a log scale but velocity and acceleration on linear
> > scales.  The following is comparable:
> >
> >
> > str(DAX <- EuStockMarkets[, 'DAX'])
> > str(DAX. <- cbind(DAX, diff(log(DAX)),
> >diff(diff(log(DAX)
> > colnames(DAX.)[2:3] <- c('vel', 'accel')
> > plot(DAX.)
> >
> >
> >   I want the first of the three panels to plot on the log scale, but
> > the other two on linear scales.  The obvious attempt does not work:
> >
> >
> > plot(DAX., log=c('y', '', ''))
> > #Error in length(log) && log != "" :
> > #  'length = 3' in coercion to 'logical(1)'
> >
> >
> >   Trying to construct my own axes isn't easy, either:
> >
> >
> > str(logDAX <- cbind(log(DAX), diff(log(DAX)),
> >diff(diff(log(DAX)
> > colnames(logDAX) <- c('logDAX', 'vel', 'accel')
> > plot(logDAX, axes=FALSE)
> > axis(1)
> > axis(2)
> >
> >
> >   I'm thinking of creating my own copy of "plot.ts", and changing 
> > it so
> > it accepts the "log" argument as a vector of length equal to ncol of the
> > ts object to be plotted AND returning an object that would allow a user
> > to call "axis" ncol times.
> >
> >
> >   Suggestions?
> >
> >
> >   Thanks,
> >   Spencer Graves
> >
> > >
> > > HTH,
> > > Eric
> > >
> > >
> > > On Mon, May 29, 2023 at 7:57 AM Spencer Graves
> > >  wrote:
> > >>
> > >> Hello, All:
> > >>
> > >>
> > >>I want to plot level, velocity, and acceleration in three 
> > >> panels with
> > >> only one x axis.  The code below does this using "layout".  However, I
> > >> want the three plot areas to be of equal size, and this won't do that:
> > >> If I stretch the plot vertically, the relative sizes of the three panels
> > >> changes.  There's probably a way to do this with ggplot2, but I have yet
> > >> to find it.
> > >>
> > >>
> > >>Suggestions?
> > >>Thanks,
> > >>Spencer Graves
> > >>
> > >>
> > >> str(AirTime <- as.numeric(time(AirPassengers)))
> > >> str(AP <- as.numeric(AirPassengers))
> > >>
> > >> def.par <- par(no.readonly = TRUE) # save default, for resetting...
> > >> (mat3x1 <- matrix(1:3, 3))
> > >> plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
> > >> layout.show(plot3x1)
> > >>
> > >> par(mar=c(0, 4.1, 4.1, 2.1))
> > >> plot(AirTime, AP, log='y', type='l', axes=FALSE,
> > >>main='AirPassengers', ylab='AirPassengers')
> > >> box(col='grey')
> > >> axis(2, las=1)
> > >>
> > >> par(mar=c(0, 4.1, 0, 2.1))
> > >> vAP <- diff(log(AP))
> > >> plot(tail(AirTime, -1), vAP, type='l',
> > >>ylab='percent increase', axes=FALSE)
> > >> box(col='grey')
> > >> axis(2, las=1)
> > >>
> > >> par(mar=c(5.1, 4.1, 0, 2.1))
> > >> plot(tail(AirTime, -2), diff(vAP), type='l',
> > >>ylab='acceleration', xlab='year',
> > >>las=1)
> > >> box(col='grey')
> > >>
> > >> par(def.par)
> > >>
> > >> __
> > >> 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 level, velocity, acceleration with one x axis

2023-05-30 Thread Eric Berger
Untested but why not

a <- cbind(log(DAX), exp(diff(log(DAX))), exp(diff(diff(log(DAX)
colnames(a) <- c("logDAX", "vel", "accel")
plot(a)


On Tue, May 30, 2023 at 1:46 PM Spencer Graves
 wrote:
>
>
>
> On 5/29/23 2:37 AM, Eric Berger wrote:
> > How about this:
> >
> > a <- cbind(AirPassengers, diff(log(AirPassengers)),
> > diff(diff(log(AirPassengers
> > colnames(a)[2:3] <- c("percent increase", "acceleration")
> > plot(a, xlab="year", main="AirPassengers")
>
>
>   My real problem is more difficult:  I'm analyzing CO2 data from Our
> World in Data (https://ourworldindata.org/co2-emissions), and I need to
> plot the CO2 data on a log scale but velocity and acceleration on linear
> scales.  The following is comparable:
>
>
> str(DAX <- EuStockMarkets[, 'DAX'])
> str(DAX. <- cbind(DAX, diff(log(DAX)),
>diff(diff(log(DAX)
> colnames(DAX.)[2:3] <- c('vel', 'accel')
> plot(DAX.)
>
>
>   I want the first of the three panels to plot on the log scale, but
> the other two on linear scales.  The obvious attempt does not work:
>
>
> plot(DAX., log=c('y', '', ''))
> #Error in length(log) && log != "" :
> #  'length = 3' in coercion to 'logical(1)'
>
>
>   Trying to construct my own axes isn't easy, either:
>
>
> str(logDAX <- cbind(log(DAX), diff(log(DAX)),
>diff(diff(log(DAX)
> colnames(logDAX) <- c('logDAX', 'vel', 'accel')
> plot(logDAX, axes=FALSE)
> axis(1)
> axis(2)
>
>
>   I'm thinking of creating my own copy of "plot.ts", and changing it 
> so
> it accepts the "log" argument as a vector of length equal to ncol of the
> ts object to be plotted AND returning an object that would allow a user
> to call "axis" ncol times.
>
>
>   Suggestions?
>
>
>   Thanks,
>   Spencer Graves
>
> >
> > HTH,
> > Eric
> >
> >
> > On Mon, May 29, 2023 at 7:57 AM Spencer Graves
> >  wrote:
> >>
> >> Hello, All:
> >>
> >>
> >>I want to plot level, velocity, and acceleration in three 
> >> panels with
> >> only one x axis.  The code below does this using "layout".  However, I
> >> want the three plot areas to be of equal size, and this won't do that:
> >> If I stretch the plot vertically, the relative sizes of the three panels
> >> changes.  There's probably a way to do this with ggplot2, but I have yet
> >> to find it.
> >>
> >>
> >>Suggestions?
> >>Thanks,
> >>Spencer Graves
> >>
> >>
> >> str(AirTime <- as.numeric(time(AirPassengers)))
> >> str(AP <- as.numeric(AirPassengers))
> >>
> >> def.par <- par(no.readonly = TRUE) # save default, for resetting...
> >> (mat3x1 <- matrix(1:3, 3))
> >> plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
> >> layout.show(plot3x1)
> >>
> >> par(mar=c(0, 4.1, 4.1, 2.1))
> >> plot(AirTime, AP, log='y', type='l', axes=FALSE,
> >>main='AirPassengers', ylab='AirPassengers')
> >> box(col='grey')
> >> axis(2, las=1)
> >>
> >> par(mar=c(0, 4.1, 0, 2.1))
> >> vAP <- diff(log(AP))
> >> plot(tail(AirTime, -1), vAP, type='l',
> >>ylab='percent increase', axes=FALSE)
> >> box(col='grey')
> >> axis(2, las=1)
> >>
> >> par(mar=c(5.1, 4.1, 0, 2.1))
> >> plot(tail(AirTime, -2), diff(vAP), type='l',
> >>ylab='acceleration', xlab='year',
> >>las=1)
> >> box(col='grey')
> >>
> >> par(def.par)
> >>
> >> __
> >> 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 level, velocity, acceleration with one x axis

2023-05-30 Thread Spencer Graves




On 5/29/23 2:37 AM, Eric Berger wrote:

How about this:

a <- cbind(AirPassengers, diff(log(AirPassengers)),
diff(diff(log(AirPassengers
colnames(a)[2:3] <- c("percent increase", "acceleration")
plot(a, xlab="year", main="AirPassengers")



	  My real problem is more difficult:  I'm analyzing CO2 data from Our 
World in Data (https://ourworldindata.org/co2-emissions), and I need to 
plot the CO2 data on a log scale but velocity and acceleration on linear 
scales.  The following is comparable:



str(DAX <- EuStockMarkets[, 'DAX'])
str(DAX. <- cbind(DAX, diff(log(DAX)),
  diff(diff(log(DAX)
colnames(DAX.)[2:3] <- c('vel', 'accel')
plot(DAX.)


	  I want the first of the three panels to plot on the log scale, but 
the other two on linear scales.  The obvious attempt does not work:



plot(DAX., log=c('y', '', ''))
#Error in length(log) && log != "" :
#  'length = 3' in coercion to 'logical(1)'


  Trying to construct my own axes isn't easy, either:


str(logDAX <- cbind(log(DAX), diff(log(DAX)),
  diff(diff(log(DAX)
colnames(logDAX) <- c('logDAX', 'vel', 'accel')
plot(logDAX, axes=FALSE)
axis(1)
axis(2)


	  I'm thinking of creating my own copy of "plot.ts", and changing it so 
it accepts the "log" argument as a vector of length equal to ncol of the 
ts object to be plotted AND returning an object that would allow a user 
to call "axis" ncol times.



  Suggestions?


  Thanks,
  Spencer Graves



HTH,
Eric


On Mon, May 29, 2023 at 7:57 AM Spencer Graves
 wrote:


Hello, All:


   I want to plot level, velocity, and acceleration in three panels with
only one x axis.  The code below does this using "layout".  However, I
want the three plot areas to be of equal size, and this won't do that:
If I stretch the plot vertically, the relative sizes of the three panels
changes.  There's probably a way to do this with ggplot2, but I have yet
to find it.


   Suggestions?
   Thanks,
   Spencer Graves


str(AirTime <- as.numeric(time(AirPassengers)))
str(AP <- as.numeric(AirPassengers))

def.par <- par(no.readonly = TRUE) # save default, for resetting...
(mat3x1 <- matrix(1:3, 3))
plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
layout.show(plot3x1)

par(mar=c(0, 4.1, 4.1, 2.1))
plot(AirTime, AP, log='y', type='l', axes=FALSE,
   main='AirPassengers', ylab='AirPassengers')
box(col='grey')
axis(2, las=1)

par(mar=c(0, 4.1, 0, 2.1))
vAP <- diff(log(AP))
plot(tail(AirTime, -1), vAP, type='l',
   ylab='percent increase', axes=FALSE)
box(col='grey')
axis(2, las=1)

par(mar=c(5.1, 4.1, 0, 2.1))
plot(tail(AirTime, -2), diff(vAP), type='l',
   ylab='acceleration', xlab='year',
   las=1)
box(col='grey')

par(def.par)

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