Re: [R] plot(aov, which=1) with different labels?

2024-06-20 Thread Duncan Murdoch

On 2024-06-20 2:01 a.m., DynV Montrealer wrote:

I need to do a non-English report including the red line from plot(aov,
which=1), which I don't know how to reproduce. I'm thinking that if I
replace the labels that it would be good (so no English remains). What I
have so far is almost what I need, the only thing that needs to change is
what's right above the plot: Residuals vs Fitted; I'd like it to either be
changed to "Résidus vs Valeurs prédites" or not be displayed. Covering up
"Residuals vs Fitted" seems like a good alternative, perhaps to do so would
require plot(aov, which=1) to be assigned in an object then modify that
object then display it. How I got to where I am:
my_aov <- aov(...) plot(my_aov, which=1, ann=FALSE) title(main="Mon titre",
xlab="Valeurs prédites", ylab="Résidus")

Thank you kindly for your help


Plotting an aov object is done by stats:::plot.lm.  From the help page 
?plot.lm, I think the value that you want to change is the "caption" 
argument, i.e.



 plot(my_aov, which=1, ann=FALSE,
   caption = "Résidus vs Valeurs prédites")
 title(xlab="Valeurs prédites", ylab="Résidus", main="Mon titre")

You can use `caption = NA` to suppress it.

Duncan Murdoch

__
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 for 10 years extrapolation

2023-10-28 Thread varin sacha via R-help
Dear Rui,

I really thank you a lot for your precious R help. It is exactly what I was 
trying to do! Once more, many thanks!

Best,
Sacha






Le vendredi 27 octobre 2023 à 09:36:18 UTC+2, Rui Barradas 
 a écrit : 





Às 19:23 de 26/10/2023, varin sacha via R-help escreveu:
> Dear R-Experts,
> 
> Here below my R code working but I don't know how to complete/finish my R 
> code to get the final plot with the extrapolation for the10 more years.
> 
> Indeed, I try to extrapolate my data with a linear fit over the next 10 
> years. So I create a date sequence for the next 10 years and store as a 
> dataframe to make the prediction possible.
> Now, I am trying to get the plot with the actual data (from year 2004 to 
> 2018) and with the 10 more years extrapolation.
> 
> Thanks for your help.
> 
> 
> date <-as.Date(c("2018-12-31", "2017-12-31", "2016-12-31", "2015-12-31", 
> "2014-12-31", "2013-12-31", "2012-12-31", "2011-12-31", "2010-12-31", 
> "2009-12-31", "2008-12-31", "2007-12-31", "2006-12-31", "2005-12-31", 
> "2004-12-31"))
>  
> value <-c(15348, 13136, 11733, 10737, 15674, 11098, 13721, 13209, 11099, 
> 10087, 14987, 11098, 13421, 9023, 12098)
>  
> model <- lm(value~date)
>  
> plot(value~date ,col="grey",pch=20,cex=1.5,main="Plot")
> abline(model,col="darkorange",lwd=2)
>  
> dfuture <- data.frame(date=seq(as.Date("2019-12-31"), by="1 year", 
> length.out=10))
>  
> predict(model,dfuture,interval="prediction")
> 
> 
> __
> 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.
Hello,

Here is a way with base R graphics. Explained in the code comments.




date <-as.Date(c("2018-12-31", "2017-12-31", "2016-12-31",
                  "2015-12-31", "2014-12-31", "2013-12-31",
                  "2012-12-31", "2011-12-31", "2010-12-31",
                  "2009-12-31", "2008-12-31", "2007-12-31",
                  "2006-12-31", "2005-12-31", "2004-12-31"))

value <-c(15348, 13136, 11733, 10737, 15674, 11098, 13721, 13209,
          11099, 10087, 14987, 11098, 13421, 9023, 12098)

model <- lm(value ~ date)

dfuture <- data.frame(date = seq(as.Date("2019-12-31"), by="1 year", 
length.out=10))



predfuture <- predict(model, dfuture, interval="prediction")
dfuture <- cbind(dfuture, predfuture)

# start the plot with the required x and y limits
xlim <- range(c(date, dfuture$date))
ylim <- range(c(value, dfuture$fit))

plot(value ~ date, col="grey", pch=20, cex=1.5, main="Plot"
      , xlim = xlim, ylim = ylim)

# abline extends the fitted line past the x value (date)
# limit making the next ten years line ugly and not even
# completely overplotting the abline drawn line
abline(model, col="darkorange", lwd=2)
lines(fit ~ date, dfuture
      # , lty = "dashed"
      , lwd=2
      , col = "black")

# if lines() is used for both the interpolated and extrapolated
# values you will have a gap between both fitted and predicted lines
# but it is closer to what you want

# get the fitted values first (interpolated values)
ypred <- predict(model)


plot(value ~ date, col="grey", pch=20, cex=1.5, main="Plot"

      , xlim = xlim, ylim = ylim)

# plot the interpolated values
lines(ypred ~ date, col="darkorange", lwd = 2)
# and now the extrapolated values
# I use normal orange to make the difference more obvious
lines(fit ~ date, dfuture, lty = "dashed", lwd=2, col = "orange")



Hope this helps,

Rui Barradas


-- 
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.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] Plot for 10 years extrapolation

2023-10-27 Thread Rui Barradas

Às 19:23 de 26/10/2023, varin sacha via R-help escreveu:

Dear R-Experts,

Here below my R code working but I don't know how to complete/finish my R code 
to get the final plot with the extrapolation for the10 more years.

Indeed, I try to extrapolate my data with a linear fit over the next 10 years. 
So I create a date sequence for the next 10 years and store as a dataframe to 
make the prediction possible.
Now, I am trying to get the plot with the actual data (from year 2004 to 2018) 
and with the 10 more years extrapolation.

Thanks for your help.


date <-as.Date(c("2018-12-31", "2017-12-31", "2016-12-31", "2015-12-31", "2014-12-31", "2013-12-31", "2012-12-31", "2011-12-31", 
"2010-12-31", "2009-12-31", "2008-12-31", "2007-12-31", "2006-12-31", "2005-12-31", "2004-12-31"))
  
value <-c(15348, 13136, 11733, 10737, 15674, 11098, 13721, 13209, 11099, 10087, 14987, 11098, 13421, 9023, 12098)
  
model <- lm(value~date)
  
plot(value~date ,col="grey",pch=20,cex=1.5,main="Plot")

abline(model,col="darkorange",lwd=2)
  
dfuture <- data.frame(date=seq(as.Date("2019-12-31"), by="1 year", length.out=10))
  
predict(model,dfuture,interval="prediction")



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

Hello,

Here is a way with base R graphics. Explained in the code comments.




date <-as.Date(c("2018-12-31", "2017-12-31", "2016-12-31",
 "2015-12-31", "2014-12-31", "2013-12-31",
 "2012-12-31", "2011-12-31", "2010-12-31",
 "2009-12-31", "2008-12-31", "2007-12-31",
 "2006-12-31", "2005-12-31", "2004-12-31"))

value <-c(15348, 13136, 11733, 10737, 15674, 11098, 13721, 13209,
  11099, 10087, 14987, 11098, 13421, 9023, 12098)

model <- lm(value ~ date)

dfuture <- data.frame(date = seq(as.Date("2019-12-31"), by="1 year", 
length.out=10))




predfuture <- predict(model, dfuture, interval="prediction")
dfuture <- cbind(dfuture, predfuture)

# start the plot with the required x and y limits
xlim <- range(c(date, dfuture$date))
ylim <- range(c(value, dfuture$fit))

plot(value ~ date, col="grey", pch=20, cex=1.5, main="Plot"
 , xlim = xlim, ylim = ylim)

# abline extends the fitted line past the x value (date)
# limit making the next ten years line ugly and not even
# completely overplotting the abline drawn line
abline(model, col="darkorange", lwd=2)
lines(fit ~ date, dfuture
  # , lty = "dashed"
  , lwd=2
  , col = "black")

# if lines() is used for both the interpolated and extrapolated
# values you will have a gap between both fitted and predicted lines
# but it is closer to what you want

# get the fitted values first (interpolated values)
ypred <- predict(model)

plot(value ~ date, col="grey", pch=20, cex=1.5, main="Plot"
 , xlim = xlim, ylim = ylim)

# plot the interpolated values
lines(ypred ~ date, col="darkorange", lwd = 2)
# and now the extrapolated values
# I use normal orange to make the difference more obvious
lines(fit ~ date, dfuture, lty = "dashed", lwd=2, col = "orange")



Hope this helps,

Rui Barradas


--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.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] Plot for 10 years extrapolation

2023-10-26 Thread Bert Gunter
Incidentally, if all you wanted to do was plot fitted values, the
predict method is kinda overkill, as it's just the fitted line from
the model. But I assume you wanted to plot CI's/PI's also, as the
example illustrated.

-- Bert

On Thu, Oct 26, 2023 at 1:56 PM Bert Gunter  wrote:
>
> from ?predict.lm:
>
> "predict.lm produces a vector of predictions or a matrix of
> predictions and bounds with column names fit, lwr, and upr if interval
> is set. "
>
> ergo:
> predict(model, dfuture, interval = "prediction")[,"fit"]  ## or [,1]
> as it's the first column in the returned matrix
>
> is your vector of predicted values that you can plot against
> dfuture$date however you would like, e.g. with different colors,
> symbols, or whatever. Exactly how you do this depends on what graphics
> package you are using. The example in ?predict.lm shows you how to do
> it with R's base graphics and overlaying prediction and confidence
> intervals.
>
> Cheers,
> Bert
>
> On Thu, Oct 26, 2023 at 11:27 AM varin sacha via R-help
>  wrote:
> >
> > Dear R-Experts,
> >
> > Here below my R code working but I don't know how to complete/finish my R 
> > code to get the final plot with the extrapolation for the10 more years.
> >
> > Indeed, I try to extrapolate my data with a linear fit over the next 10 
> > years. So I create a date sequence for the next 10 years and store as a 
> > dataframe to make the prediction possible.
> > Now, I am trying to get the plot with the actual data (from year 2004 to 
> > 2018) and with the 10 more years extrapolation.
> >
> > Thanks for your help.
> >
> > 
> > date <-as.Date(c("2018-12-31", "2017-12-31", "2016-12-31", "2015-12-31", 
> > "2014-12-31", "2013-12-31", "2012-12-31", "2011-12-31", "2010-12-31", 
> > "2009-12-31", "2008-12-31", "2007-12-31", "2006-12-31", "2005-12-31", 
> > "2004-12-31"))
> >
> > value <-c(15348, 13136, 11733, 10737, 15674, 11098, 13721, 13209, 11099, 
> > 10087, 14987, 11098, 13421, 9023, 12098)
> >
> > model <- lm(value~date)
> >
> > plot(value~date ,col="grey",pch=20,cex=1.5,main="Plot")
> > abline(model,col="darkorange",lwd=2)
> >
> > dfuture <- data.frame(date=seq(as.Date("2019-12-31"), by="1 year", 
> > length.out=10))
> >
> > predict(model,dfuture,interval="prediction")
> > 
> >
> > __
> > 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 for 10 years extrapolation

2023-10-26 Thread Bert Gunter
from ?predict.lm:

"predict.lm produces a vector of predictions or a matrix of
predictions and bounds with column names fit, lwr, and upr if interval
is set. "

ergo:
predict(model, dfuture, interval = "prediction")[,"fit"]  ## or [,1]
as it's the first column in the returned matrix

is your vector of predicted values that you can plot against
dfuture$date however you would like, e.g. with different colors,
symbols, or whatever. Exactly how you do this depends on what graphics
package you are using. The example in ?predict.lm shows you how to do
it with R's base graphics and overlaying prediction and confidence
intervals.

Cheers,
Bert

On Thu, Oct 26, 2023 at 11:27 AM varin sacha via R-help
 wrote:
>
> Dear R-Experts,
>
> Here below my R code working but I don't know how to complete/finish my R 
> code to get the final plot with the extrapolation for the10 more years.
>
> Indeed, I try to extrapolate my data with a linear fit over the next 10 
> years. So I create a date sequence for the next 10 years and store as a 
> dataframe to make the prediction possible.
> Now, I am trying to get the plot with the actual data (from year 2004 to 
> 2018) and with the 10 more years extrapolation.
>
> Thanks for your help.
>
> 
> date <-as.Date(c("2018-12-31", "2017-12-31", "2016-12-31", "2015-12-31", 
> "2014-12-31", "2013-12-31", "2012-12-31", "2011-12-31", "2010-12-31", 
> "2009-12-31", "2008-12-31", "2007-12-31", "2006-12-31", "2005-12-31", 
> "2004-12-31"))
>
> value <-c(15348, 13136, 11733, 10737, 15674, 11098, 13721, 13209, 11099, 
> 10087, 14987, 11098, 13421, 9023, 12098)
>
> model <- lm(value~date)
>
> plot(value~date ,col="grey",pch=20,cex=1.5,main="Plot")
> abline(model,col="darkorange",lwd=2)
>
> dfuture <- data.frame(date=seq(as.Date("2019-12-31"), by="1 year", 
> length.out=10))
>
> predict(model,dfuture,interval="prediction")
> 
>
> __
> 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 to a device and examine the plot?

2023-10-15 Thread Shu Fai Cheung
Thanks for the suggestion. I believe it is exactly what I need. I will
try this function. Thanks!

Regards,
Shu Fai

On Mon, Oct 16, 2023 at 3:39 AM Paul Murrell  wrote:
>
> Hi
>
> You could also look at dev.capture(), depending on which screen device
> you are using.
>
> Paul
>
> On 16/10/23 05:24, Duncan Murdoch wrote:
> > On 15/10/2023 12:05 p.m., Shu Fai Cheung wrote:
> >  > Let me clarify my question:
> >  >
> >  > plot.new()
> >  > polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
> >  >
> >  > If the device is an on-screen device, can I check whether a
> > particular area
> >  > has anything drawn on it, or, to be precise, whether the color of a
> >  > particular area has all pixels equal to the background color. That is, if
> >  > the background is white, can I know whether a particular area is white?
> >  >
> >  > E.g., in the case above, the area bounded by rect(0, 0, .25, .25) is
> >  > completely white, while the area bounded by rect(0, 0, .75, .75) is not
> >  > because part of border of the polygon, black by default, has been
> > drawn in
> >  > this area.
> >  >
> >  > If the device is an image file, then I can check the color of a pixel. I
> >  > would like to know whether I can do the same with an on-screen device.
> >  >
> >
> > I think the answer is that you can't do that in general. However, in
> > general you can copy a plot to a different device using dev.copy() and
> > examine it there. It won't be pixel-by-pixel identical, but will
> > contain the same components, likely with slightly different scaling and
> > positioning if the new device isn't the same as the old one.
> >
> > You can also save the commands that drew the plot using recordPlot() and
> > redraw it using replayPlot() (which is essentially what dev.copy()
> > does), but the format of the object saved by recordPlot() is not
> > documented, and is subject to change with R version changes.
> >
> > Duncan Murdoch
> >
> > __
> > 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.
>
> --
> Dr Paul Murrell
> Te Kura Tatauranga | Department of Statistics
> Waipapa Taumata Rau | The University of Auckland
> Private Bag 92019, Auckland 1142, New Zealand
> 64 9 3737599 x85392
> p...@stat.auckland.ac.nz
> www.stat.auckland.ac.nz/~paul/
>

__
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 to a device and examine the plot?

2023-10-15 Thread Shu Fai Cheung
Thanks a lot for introducing these functions! I am not aware of them
but it seems that they can help me to do what I want to do.

Regards,
Shu Fai

Regards,
Shu Fai Cheung (張樹輝)


On Mon, Oct 16, 2023 at 12:24 AM Duncan Murdoch
 wrote:
>
> On 15/10/2023 12:05 p.m., Shu Fai Cheung wrote:
> > Let me clarify my question:
> >
> > plot.new()
> > polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
> >
> > If the device is an on-screen device, can I check whether a particular area
> > has anything drawn on it, or, to be precise, whether the color of a
> > particular area has all pixels equal to the background color. That is, if
> > the background is white, can I know whether a particular area is white?
> >
> > E.g.,  in the case above, the area bounded by rect(0, 0, .25, .25) is
> > completely white, while the area bounded by rect(0, 0, .75, .75) is not
> > because part of border of the polygon, black by default, has been drawn in
> > this area.
> >
> > If the device is an image file, then I can check the color of a pixel. I
> > would like to know whether I can do the same with an on-screen device.
> >
>
> I think the answer is that you can't do that in general.  However, in
> general you can copy a plot to a different device using dev.copy() and
> examine it there.  It won't be pixel-by-pixel identical, but will
> contain the same components, likely with slightly different scaling and
> positioning if the new device isn't the same as the old one.
>
> You can also save the commands that drew the plot using recordPlot() and
> redraw it using replayPlot() (which is essentially what dev.copy()
> does), but the format of the object saved by recordPlot() is not
> documented, and is subject to change with R version changes.
>
> Duncan Murdoch
>

__
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 to a device and examine the plot?

2023-10-15 Thread Paul Murrell

Hi

You could also look at dev.capture(), depending on which screen device 
you are using.


Paul

On 16/10/23 05:24, Duncan Murdoch wrote:

On 15/10/2023 12:05 p.m., Shu Fai Cheung wrote:
 > Let me clarify my question:
 >
 > plot.new()
 > polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
 >
 > If the device is an on-screen device, can I check whether a 
particular area

 > has anything drawn on it, or, to be precise, whether the color of a
 > particular area has all pixels equal to the background color. That is, if
 > the background is white, can I know whether a particular area is white?
 >
 > E.g., in the case above, the area bounded by rect(0, 0, .25, .25) is
 > completely white, while the area bounded by rect(0, 0, .75, .75) is not
 > because part of border of the polygon, black by default, has been 
drawn in

 > this area.
 >
 > If the device is an image file, then I can check the color of a pixel. I
 > would like to know whether I can do the same with an on-screen device.
 >

I think the answer is that you can't do that in general. However, in
general you can copy a plot to a different device using dev.copy() and
examine it there. It won't be pixel-by-pixel identical, but will
contain the same components, likely with slightly different scaling and
positioning if the new device isn't the same as the old one.

You can also save the commands that drew the plot using recordPlot() and
redraw it using replayPlot() (which is essentially what dev.copy()
does), but the format of the object saved by recordPlot() is not
documented, and is subject to change with R version changes.

Duncan Murdoch

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


--
Dr Paul Murrell
Te Kura Tatauranga | Department of Statistics
Waipapa Taumata Rau | The University of Auckland
Private Bag 92019, Auckland 1142, New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
www.stat.auckland.ac.nz/~paul/

__
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 to a device and examine the plot?

2023-10-15 Thread Duncan Murdoch

On 15/10/2023 12:05 p.m., Shu Fai Cheung wrote:

Let me clarify my question:

plot.new()
polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))

If the device is an on-screen device, can I check whether a particular area
has anything drawn on it, or, to be precise, whether the color of a
particular area has all pixels equal to the background color. That is, if
the background is white, can I know whether a particular area is white?

E.g.,  in the case above, the area bounded by rect(0, 0, .25, .25) is
completely white, while the area bounded by rect(0, 0, .75, .75) is not
because part of border of the polygon, black by default, has been drawn in
this area.

If the device is an image file, then I can check the color of a pixel. I
would like to know whether I can do the same with an on-screen device.



I think the answer is that you can't do that in general.  However, in 
general you can copy a plot to a different device using dev.copy() and 
examine it there.  It won't be pixel-by-pixel identical, but will 
contain the same components, likely with slightly different scaling and 
positioning if the new device isn't the same as the old one.


You can also save the commands that drew the plot using recordPlot() and 
redraw it using replayPlot() (which is essentially what dev.copy() 
does), but the format of the object saved by recordPlot() is not 
documented, and is subject to change with R version changes.


Duncan Murdoch

__
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 to a device and examine the plot?

2023-10-15 Thread Shu Fai Cheung
Let me clarify my question:

plot.new()
polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))

If the device is an on-screen device, can I check whether a particular area
has anything drawn on it, or, to be precise, whether the color of a
particular area has all pixels equal to the background color. That is, if
the background is white, can I know whether a particular area is white?

E.g.,  in the case above, the area bounded by rect(0, 0, .25, .25) is
completely white, while the area bounded by rect(0, 0, .75, .75) is not
because part of border of the polygon, black by default, has been drawn in
this area.

If the device is an image file, then I can check the color of a pixel. I
would like to know whether I can do the same with an on-screen device.

Thanks.

Regards,
Shu Fai


On Sun, Oct 15, 2023 at 11:44 PM Shu Fai Cheung 
wrote:

> Sorry that I did not make my question clear enough.
>
> If the device is file based (e.g., a PNG file), then I believe I can do
> that, by using functions that can inspect an image. This is the solution I
> originally wanted to try. However, it requires creating a file in the
> process.
>
> I would like to see whether it is possible to inspect the canvas if the
> device is an on-screen one, like the pop-up window in R for Windows.
>
> Regards,
> Shu Fai
>
>
> On Sun, Oct 15, 2023 at 11:31 PM Jeff Newmiller 
> wrote:
>
>> This question is not clear to me. What is it you hope to retrieve from
>> the device?
>>
>> Note that the type of device in your example is system-dependent. The
>> content in a png() would be different than the content in a win.graph()
>> device.
>>
>> On October 15, 2023 8:04:00 AM PDT, Shu Fai Cheung <
>> shufai.che...@gmail.com> wrote:
>> >Hi All,
>> >
>> >I want to inspect the content of a plot generated by another function.
>> >
>> >For example:
>> >
>> >plot.new()
>> >polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
>> >
>> >A polygon will be drawn. If I do not know what has been done to generate
>> >the plot, is it possible to query the content in the active device?
>> >
>> >Regards,
>> >Shu Fai
>> >
>> >   [[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.
>>
>

[[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 to a device and examine the plot?

2023-10-15 Thread Shu Fai Cheung
Sorry that I did not make my question clear enough.

If the device is file based (e.g., a PNG file), then I believe I can do
that, by using functions that can inspect an image. This is the solution I
originally wanted to try. However, it requires creating a file in the
process.

I would like to see whether it is possible to inspect the canvas if the
device is an on-screen one, like the pop-up window in R for Windows.

Regards,
Shu Fai


On Sun, Oct 15, 2023 at 11:31 PM Jeff Newmiller 
wrote:

> This question is not clear to me. What is it you hope to retrieve from the
> device?
>
> Note that the type of device in your example is system-dependent. The
> content in a png() would be different than the content in a win.graph()
> device.
>
> On October 15, 2023 8:04:00 AM PDT, Shu Fai Cheung <
> shufai.che...@gmail.com> wrote:
> >Hi All,
> >
> >I want to inspect the content of a plot generated by another function.
> >
> >For example:
> >
> >plot.new()
> >polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
> >
> >A polygon will be drawn. If I do not know what has been done to generate
> >the plot, is it possible to query the content in the active device?
> >
> >Regards,
> >Shu Fai
> >
> >   [[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.
>

[[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 to a device and examine the plot?

2023-10-15 Thread Jeff Newmiller via R-help
This question is not clear to me. What is it you hope to retrieve from the 
device?

Note that the type of device in your example is system-dependent. The content 
in a png() would be different than the content in a win.graph() device.

On October 15, 2023 8:04:00 AM PDT, Shu Fai Cheung  
wrote:
>Hi All,
>
>I want to inspect the content of a plot generated by another function.
>
>For example:
>
>plot.new()
>polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5))
>
>A polygon will be drawn. If I do not know what has been done to generate
>the plot, is it possible to query the content in the active device?
>
>Regards,
>Shu Fai
>
>   [[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.


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

2023-05-31 Thread Deepayan Sarkar
I think your proposal of modifying plot.ts() to allow 'log' to be
vectorized would be the most natural solution here.

For what it's worth, the details of the implementation and the fact
that you can supply a panel function allows an ugly hack:

pfun <- function(...) {
e <- parent.frame()
e$log <- ""
lines(...)
}
plot(DAX., log = "y", panel = pfun)

This would need to be modified to include a counter in more
complicated cases; we can do without because only the first panel has
a log scale in this example.

-Deepayan

On Thu, Jun 1, 2023 at 12:53 AM Spencer Graves
 wrote:
>
>
>
> On 5/31/23 2:12 PM, Viechtbauer, Wolfgang (NP) wrote:
> > How about using the same 'mar' for all plots, but adding an outer margin?
> >
> > DAX <- EuStockMarkets[, 'DAX']
> > DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX
> > colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
> > head(DAX.)
> >
> > par(mfrow=c(3,1), mar=c(1,4.5,0,2), oma=c(3,0,1,0))
> >
> > plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
> > axis(2)
> > box(col='grey')
> >
> > plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
> > axis(2)
> > box(col='grey')
> >
> > plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
> > axis(2)
> > box(col='grey')
> > axis(1)
> >
> > Best,
> > Wolfgang
>
>
> That's exactly what I needed.
>
>
> Thanks, Spencer
> >
>
> >> -Original Message-
> >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer 
> >> Graves
> >> Sent: Wednesday, 31 May, 2023 17:45
> >> To: Eric Berger
> >> Cc: r-help
> >> Subject: Re: [R] plot level, velocity, acceleration with one x axis
> >>
> >> On 5/31/23 9:20 AM, Eric Berger wrote:
> >>> I sent you an updated response to deal with the redundant copies of the 
> >>> x-axis.
> >>> Re-sending.
> >>>
> >> par(mfrow=c(3,1))
> >> plot(DAX.[, 1], log='y', ylab='DAX', xaxt="n")
> >> plot(DAX.[, 2], ylab='vel (%)', xaxt="n")
> >> plot(DAX.[, 3], ylab='accel (%)')
> >>
> >>I got that.  The primary problem with that is that most of the
> >> vertical space is reserved for axis labels, whether they are printed or
> >> not.  If I squeeze the vertical dimension of the plot, I get, "figure
> >> margins too large".  To control that, I need to set "mar" separately for
> >> each panel, and then the plot regions for each are not the same size.
> >> Using the "layout" function instead of "mfrow" is better, but I don't
> >> see now to make that work consistently without fixing the aspect ratio.
> >> There may be a way in the tidyverse, but I haven't found it yet.  The
> >> only solution I've found so far that makes sense to me is to modify the
> >> code for plot.ts to accept a vector for the log argument, with the
> >> constraint that length(lot) = either 1 or ncol(x) and returning
> >> invisibly an object that would make it feasible for a user to call
> >> axis(2, ...) once for each vertical axis to handle cases where someone
> >> wanted to a vertical scale different from linear and log.  I'd want to
> >> make sure that lines.ts also works with this, because I want to add fits
> >> and predictions.
> >>
> >>Comments?
> >>Thanks,
> >>Spencer Graves
> >>
> >> ** With either of the following plots, if I adjust the aspect ratio by
> >> enlarging or reducing the vertical dimension of the plot, the relative
> >> sizes of the plot regions change.
> >>
> >> DAX <- EuStockMarkets[, 'DAX']
> >> DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX
> >> colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
> >> head(DAX.)
> >>
> >> plot(DAX., log='xy')
> >>
> >> op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
> >> plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
> >> axis(2)
> >> box(col='grey')
> >> par(mar=c(0, 4.1, 0, 2.1))
> >> plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
> >> axis(2)
> >> box(col='grey')
> >> par(mar=c(5.1, 4.1, 0, 2.1))
> >> plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
> >> axis(2)
> >> box(col='grey')
> >> axis(1)
> >> par(op)
>
> __
> 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-31 Thread Spencer Graves




On 5/31/23 2:12 PM, Viechtbauer, Wolfgang (NP) wrote:

How about using the same 'mar' for all plots, but adding an outer margin?

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

par(mfrow=c(3,1), mar=c(1,4.5,0,2), oma=c(3,0,1,0))

plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
axis(2)
box(col='grey')

plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
axis(2)
box(col='grey')

plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
axis(2)
box(col='grey')
axis(1)

Best,
Wolfgang



That's exactly what I needed.


Thanks, Spencer





-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves
Sent: Wednesday, 31 May, 2023 17:45
To: Eric Berger
Cc: r-help
Subject: Re: [R] plot level, velocity, acceleration with one x axis

On 5/31/23 9:20 AM, Eric Berger wrote:

I sent you an updated response to deal with the redundant copies of the x-axis.
Re-sending.


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

  I got that.  The primary problem with that is that most of the
vertical space is reserved for axis labels, whether they are printed or
not.  If I squeeze the vertical dimension of the plot, I get, "figure
margins too large".  To control that, I need to set "mar" separately for
each panel, and then the plot regions for each are not the same size.
Using the "layout" function instead of "mfrow" is better, but I don't
see now to make that work consistently without fixing the aspect ratio.
There may be a way in the tidyverse, but I haven't found it yet.  The
only solution I've found so far that makes sense to me is to modify the
code for plot.ts to accept a vector for the log argument, with the
constraint that length(lot) = either 1 or ncol(x) and returning
invisibly an object that would make it feasible for a user to call
axis(2, ...) once for each vertical axis to handle cases where someone
wanted to a vertical scale different from linear and log.  I'd want to
make sure that lines.ts also works with this, because I want to add fits
and predictions.

  Comments?
  Thanks,
  Spencer Graves

** With either of the following plots, if I adjust the aspect ratio by
enlarging or reducing the vertical dimension of the plot, the relative
sizes of the plot regions change.

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

plot(DAX., log='xy')

op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
axis(2)
box(col='grey')
par(mar=c(0, 4.1, 0, 2.1))
plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
axis(2)
box(col='grey')
par(mar=c(5.1, 4.1, 0, 2.1))
plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
axis(2)
box(col='grey')
axis(1)
par(op)


__
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-31 Thread Viechtbauer, Wolfgang (NP)
How about using the same 'mar' for all plots, but adding an outer margin?

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

par(mfrow=c(3,1), mar=c(1,4.5,0,2), oma=c(3,0,1,0))

plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
axis(2)
box(col='grey')

plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
axis(2)
box(col='grey')

plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
axis(2)
box(col='grey')
axis(1)

Best,
Wolfgang

>-Original Message-
>From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Spencer Graves
>Sent: Wednesday, 31 May, 2023 17:45
>To: Eric Berger
>Cc: r-help
>Subject: Re: [R] plot level, velocity, acceleration with one x axis
>
>On 5/31/23 9:20 AM, Eric Berger wrote:
>> I sent you an updated response to deal with the redundant copies of the 
>> x-axis.
>> Re-sending.
>>
>par(mfrow=c(3,1))
>plot(DAX.[, 1], log='y', ylab='DAX', xaxt="n")
>plot(DAX.[, 2], ylab='vel (%)', xaxt="n")
>plot(DAX.[, 3], ylab='accel (%)')
>
> I got that.  The primary problem with that is that most of the
>vertical space is reserved for axis labels, whether they are printed or
>not.  If I squeeze the vertical dimension of the plot, I get, "figure
>margins too large".  To control that, I need to set "mar" separately for
>each panel, and then the plot regions for each are not the same size.
>Using the "layout" function instead of "mfrow" is better, but I don't
>see now to make that work consistently without fixing the aspect ratio.
>There may be a way in the tidyverse, but I haven't found it yet.  The
>only solution I've found so far that makes sense to me is to modify the
>code for plot.ts to accept a vector for the log argument, with the
>constraint that length(lot) = either 1 or ncol(x) and returning
>invisibly an object that would make it feasible for a user to call
>axis(2, ...) once for each vertical axis to handle cases where someone
>wanted to a vertical scale different from linear and log.  I'd want to
>make sure that lines.ts also works with this, because I want to add fits
>and predictions.
>
> Comments?
> Thanks,
> Spencer Graves
>
>** With either of the following plots, if I adjust the aspect ratio by
>enlarging or reducing the vertical dimension of the plot, the relative
>sizes of the plot regions change.
>
>DAX <- EuStockMarkets[, 'DAX']
>DAX. <- cbind(DAX, diff(log(DAX)), diff(diff(log(DAX
>colnames(DAX.) <- c("DAX", 'vel (%)', 'accel (%)')
>head(DAX.)
>
>plot(DAX., log='xy')
>
>op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
>plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
>axis(2)
>box(col='grey')
>par(mar=c(0, 4.1, 0, 2.1))
>plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
>axis(2)
>box(col='grey')
>par(mar=c(5.1, 4.1, 0, 2.1))
>plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
>axis(2)
>box(col='grey')
>axis(1)
>par(op)
__
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-31 Thread Spencer Graves




On 5/31/23 9:20 AM, Eric Berger wrote:

I sent you an updated response to deal with the redundant copies of the x-axis.
Re-sending.


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


	  I got that.  The primary problem with that is that most of the 
vertical space is reserved for axis labels, whether they are printed or 
not.  If I squeeze the vertical dimension of the plot, I get, "figure 
margins too large".  To control that, I need to set "mar" separately for 
each panel, and then the plot regions for each are not the same size. 
Using the "layout" function instead of "mfrow" is better, but I don't 
see now to make that work consistently without fixing the aspect ratio. 
There may be a way in the tidyverse, but I haven't found it yet.  The 
only solution I've found so far that makes sense to me is to modify the 
code for plot.ts to accept a vector for the log argument, with the 
constraint that length(lot) = either 1 or ncol(x) and returning 
invisibly an object that would make it feasible for a user to call 
axis(2, ...) once for each vertical axis to handle cases where someone 
wanted to a vertical scale different from linear and log.  I'd want to 
make sure that lines.ts also works with this, because I want to add fits 
and predictions.



  Comments?
  Thanks,
  Spencer Graves


** With either of the following plots, if I adjust the aspect ratio by 
enlarging or reducing the vertical dimension of the plot, the relative 
sizes of the plot regions change.



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

plot(DAX., log='xy')

op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
plot(DAX.[, 1], log='y', ylab='DAX', axes=FALSE)
axis(2)
box(col='grey')
par(mar=c(0, 4.1, 0, 2.1))
plot(DAX.[, 2], ylab='vel (%)', axes=FALSE)
axis(2)
box(col='grey')
par(mar=c(5.1, 4.1, 0, 2.1))
plot(DAX.[, 3], ylab='accel (%)', axes=FALSE)
axis(2)
box(col='grey')
axis(1)
par(op)


> sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.7.7

Matrix products: default
BLAS: 
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 

LAPACK: 
/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; 
 LAPACK version 3.11.0


locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.3.0  tools_4.3.0 rstudioapi_0.14



On Wed, May 31, 2023 at 4:27 PM Spencer Graves
 wrote:




On 5/30/23 10:23 AM, Eric Berger wrote:

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 (%)')


   Most of the space is consumed with two extraneous copies of the axis.
   We can get around that with three calls to par:


op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
plot(DAX.[, 1], log='y', ylab='DAX')
par(mar=c(0, 4.1, 0, 2.1))
plot(DAX.[, 2], ylab='vel (%)')
par(mar=c(5.1, 4.1, 0, 2.1))
plot(DAX.[, 3], ylab='accel (%)')
par(op)


   However, the three panels are NOT equal in size:  roughly 30% vs. 44%
vs. 26%.  I can get closer using layout, but if I change the aspect
ratio, it changes the relationship between the heights of the three
panels.


   That's the problem I'm trying to solve.  It's also why it makes sense
to me to modify plot.ts to accept a vector for the log argument, with
the constraint that length(lot) = either 1 or ncol(x).


   There may be a way to do it using gglot2 / the tidyverse, but I'm not
facile with that, and my web searches have so far failed to produce
anything better than modifying plot.ts.R (and then submitting such with
compatible changes to plot.ts.Rd), as I suggested earlier.


   ???
   Thanks,
   Spencer



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 

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

2023-05-31 Thread Eric Berger
I sent you an updated response to deal with the redundant copies of the x-axis.
Re-sending.

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


On Wed, May 31, 2023 at 4:27 PM Spencer Graves
 wrote:
>
>
>
> On 5/30/23 10:23 AM, Eric Berger wrote:
> > 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 (%)')
>
>   Most of the space is consumed with two extraneous copies of the 
> axis.
>   We can get around that with three calls to par:
>
>
> op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
> plot(DAX.[, 1], log='y', ylab='DAX')
> par(mar=c(0, 4.1, 0, 2.1))
> plot(DAX.[, 2], ylab='vel (%)')
> par(mar=c(5.1, 4.1, 0, 2.1))
> plot(DAX.[, 3], ylab='accel (%)')
> par(op)
>
>
>   However, the three panels are NOT equal in size:  roughly 30% vs. 
> 44%
> vs. 26%.  I can get closer using layout, but if I change the aspect
> ratio, it changes the relationship between the heights of the three
> panels.
>
>
>   That's the problem I'm trying to solve.  It's also why it makes 
> sense
> to me to modify plot.ts to accept a vector for the log argument, with
> the constraint that length(lot) = either 1 or ncol(x).
>
>
>   There may be a way to do it using gglot2 / the tidyverse, but I'm 
> not
> facile with that, and my web searches have so far failed to produce
> anything better than modifying plot.ts.R (and then submitting such with
> compatible changes to plot.ts.Rd), as I suggested earlier.
>
>
>   ???
>   Thanks,
>   Spencer
>
> >
> > 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 

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

2023-05-31 Thread Spencer Graves




On 5/30/23 10:23 AM, Eric Berger wrote:

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 (%)')


	  Most of the space is consumed with two extraneous copies of the axis. 
 We can get around that with three calls to par:



op <- par(mfrow=c(3,1), mar=c(0, 4.1, 4.1, 2.1))
plot(DAX.[, 1], log='y', ylab='DAX')
par(mar=c(0, 4.1, 0, 2.1))
plot(DAX.[, 2], ylab='vel (%)')
par(mar=c(5.1, 4.1, 0, 2.1))
plot(DAX.[, 3], ylab='accel (%)')
par(op)


	  However, the three panels are NOT equal in size:  roughly 30% vs. 44% 
vs. 26%.  I can get closer using layout, but if I change the aspect 
ratio, it changes the relationship between the heights of the three 
panels.



	  That's the problem I'm trying to solve.  It's also why it makes sense 
to me to modify plot.ts to accept a vector for the log argument, with 
the constraint that length(lot) = either 1 or ncol(x).



	  There may be a way to do it using gglot2 / the tidyverse, but I'm not 
facile with that, and my web searches have so far failed to produce 
anything better than modifying plot.ts.R (and then submitting such with 
compatible changes to plot.ts.Rd), as I suggested earlier.



  ???
  Thanks,
  Spencer



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 

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

2023-05-31 Thread Eric Berger
Slight modification to have the xaxt ticks and labels only appear on
the bottom chart

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


On Tue, May 30, 2023 at 6:23 PM Eric Berger  wrote:
>
> 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 

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


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

2023-05-29 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")



That's it.  Thanks.  sg



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-29 Thread Eric Berger
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")

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 R graphs in aws

2023-04-23 Thread Hasan Diwan
Alternatively, you can put R-studio server on AWS by going to
https://www.louisaslett.com/RStudio_AMI/. -- H

On Thu, 20 Apr 2023 at 04:58, Duncan Murdoch 
wrote:

> On 20/04/2023 7:43 a.m., Naresh Gurbuxani wrote:
> > In my Amazon Web Services (AWS) account, I use R via emacs launched from
> terminal. While R computations work well, viewing graphs is inconvenient.
> I am not able to use screen device.  I can send graphs to a png or pdf
> file, then open the file.
> >
> > I would like a setup where code is run in one window while graphs are
> displayed in another window.  Has anyone created a setup like this?
>
> You don't say which OS's you are running, but if you can run an X server
> on your local machine, the remote R process should be able to display
> graphs there (as long as it is running on a Unix-alike).
>
> Duncan Murdoch
>
> __
> 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.
>


-- 
OpenPGP: https://hasan.d8u.us/openpgp.asc
If you wish to request my time, please do so using
*bit.ly/hd1AppointmentRequest
*.
Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest
*.

Sent
from my mobile device
Envoye de mon portable

[[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 R graphs in aws

2023-04-20 Thread Duncan Murdoch

On 20/04/2023 7:43 a.m., Naresh Gurbuxani wrote:

In my Amazon Web Services (AWS) account, I use R via emacs launched from 
terminal. While R computations work well, viewing graphs is inconvenient.  I am 
not able to use screen device.  I can send graphs to a png or pdf file, then 
open the file.

I would like a setup where code is run in one window while graphs are displayed 
in another window.  Has anyone created a setup like this?


You don't say which OS's you are running, but if you can run an X server 
on your local machine, the remote R process should be able to display 
graphs there (as long as it is running on a Unix-alike).


Duncan Murdoch

__
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 a line using ggplot2

2022-12-08 Thread Ebert,Timothy Aaron
A number of problems.
The variable names are not helpful. PointEstx is not a point it is a value. I 
need an x and a y coordinate for a point.
row1 is not defined
While there is a function data.frame(), there is no data_frame(). Making this 
change gives an error that row1 is not defined. I solved the problem with 
row1<-row2+1.

The ggplot statement looks wrong.

Does this give you what you need?
ggplot(linedata,aes(x=PointEstx, y=PointEsty)) + geom_line()

Note I changed the comma to a plus sign and changed the brackets.

Regards,
Tim


-Original Message-
From: R-help  On Behalf Of Sorkin, John
Sent: Thursday, December 8, 2022 8:06 PM
To: r-help@r-project.org (r-help@r-project.org) 
Subject: [R] Plot a line using ggplot2

[External Email]

Colleagues,

I am trying to plot a simple line using ggplot2. I get the axes, but I don't 
get the line. Please let me know what my error I am making.
Thank you,
John

# Define x and y values
PointEstx <- Estx+1.96*SE
PointEsty  <- 1

row2 <- cbind(PointEstx,PointEsty)
linedata<- data_frame(rbind(row1,row2))
linedata
# make sure we have a data frame
class(linedata)

#plot the data
ggplot(linedata,aes(x=PointEstx, y=PointEsty), geom_line())





__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=05%7C01%7Ctebert%40ufl.edu%7C5695e850b24347d9fcf908dad9818f28%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638061447740857132%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=KhRB4ZHKsoVlPRsAnufXXzfiJyRBEEv32P7bcAAiGBo%3Dreserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=05%7C01%7Ctebert%40ufl.edu%7C5695e850b24347d9fcf908dad9818f28%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638061447740857132%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=DPlvmxCIwlF1WqKWawzSmJbosiFGjnLwFIMKK7hFAco%3Dreserved=0
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 a line using ggplot2

2022-12-08 Thread Jeff Newmiller
Please run your code before you send it. Your example is not reproducible.

library(ggplot2)

linedata<- data.frame(
  PointEstx = c( 1, 2 )
, PointEsty = c( 1, 1.5 )
)
# make sure we have a data frame
str(linedata)

#plot the data
ggplot(
  linedata
, aes( x = PointEstx
 , y = PointEsty
 )
) + geom_line()

On December 8, 2022 5:05:47 PM PST, "Sorkin, John"  
wrote:
>Colleagues,
>
>I am trying to plot a simple line using ggplot2. I get the axes, but I don't 
>get the line. Please let me know what my error I am making.
>Thank you,
>John
>
># Define x and y values
>PointEstx <- Estx+1.96*SE
>PointEsty  <- 1
>
>row2 <- cbind(PointEstx,PointEsty)
>linedata<- data_frame(rbind(row1,row2))
>linedata
># make sure we have a data frame
>class(linedata)
>
>#plot the data
>ggplot(linedata,aes(x=PointEstx, y=PointEsty), geom_line())
>
>
>
>
>
>__
>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.


Re: [R] Plot by month

2022-02-27 Thread Jim Lemon
Hi ektaraK,
Here is a step by step way to create an example and get your plot:

# make up a lot of dates
dates<-as.Date("2021-1-1")+sample(0:364,100)
# make up the temperatures
temps<-runif(100,0,40)
# create a data frame
mydf<-data.frame(date=dates,temp=temps)
# create a month variable
mydf$month<-factor(format(mydf$date,"%b"),levels=month.abb)
# calculate mean temperature for months
temp_x_month<-by(mydf$temp,mydf$month,mean)
# create a factor of the months of the year for plotting
months<-factor(month.abb,levels=month.abb)
# plot mean temperature by month
plot(months,temp_x_month,main="Mean temperature by month")

You may only need to apply the last three steps to your data.

Jim

On Sun, Feb 27, 2022 at 1:07 AM Ebert,Timothy Aaron  wrote:
>
> I did not get the data  but I was wondering what you have already tried.
> Try group_by() function
> Try fill= or color= in the aes() statement in ggplot.
>
> What is the goal?
> Do you want lines, bars, or dots?
>
> Is this a class?
>
> Tim
>
> -Original Message-
> From: R-help  On Behalf Of ektaraful
> Sent: Saturday, February 26, 2022 2:00 AM
> To: r-help@r-project.org
> Subject: [R] Plot by month
>
> [External Email]
>
> Hi,
>
> I want to plot temp data from a csv file by month. Can you help me how I can 
> do it in R?
>
> A sample csv file is attached herewith. Please use left hand data.
>
> Thanks.
> ektaraK
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=JeHylIm3ibHTYNZ-mLAAkF4JTrj_xyBnd0IQBZDJvV6HeovFeOLa5GwBe0LLBOwN=WJLtDEQ05d0kvlWFlrGCadjyBvwqCm_j37wsJ-CObyA=
> PLEASE do read the posting guide 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=JeHylIm3ibHTYNZ-mLAAkF4JTrj_xyBnd0IQBZDJvV6HeovFeOLa5GwBe0LLBOwN=QyEPln_51yStVY2Ec1hcAqygLeEh1CNf5JJT_vv1dto=
> 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] Plot NUTS regions with color

2021-06-23 Thread Bert Gunter
I suggest you post this in the r-sig-geo list rather than here. The
expertise you seek is more likely to be there.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Jun 23, 2021 at 10:36 AM Phillips Rogfield 
wrote:

> Dear R-help ML,
>
> I have downloaded the NUTS shapefiles from here:
>
> https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts
>
> I can load them with the following code:
>
> library(rgdal)
> shp_bdir <- [PATH TO SHAPE FILE]
> layername <- "NUTS_RG_01M_2021_4326"
> shp_folder <- file.path(shp_bdir, paste0(layername,".shp"))
> EU_NUTS <- readOGR(dsn = shp_folder, layer = layername)
>
> Then I can plot the regions with:
>
> plot(EU_NUTS)
>
> Now I have a list of NUTS - 3 Level, for example:
>
> l <- c("AT223", "AT212", "AT212", "AT121")
>
> I would like a plot where the NUTS regions are colored, and the more a
> particular NUTS is present is the list, the darker its color.
>
> For example "AT212" should be darker than "AT223", because the former is
> present two times in the list.
>
> How can I achieve that?
>
> Thank you and best regards.
>
>
> [[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.


Re: [R] Plot GEE confindence interval band ggplot2

2021-06-01 Thread Rui Barradas

Hello,

I don't know if the following is what you want but it gives confidence 
bars. The error in your code is to have Esp as id.



dat$Id <- as.integer(factor(dat$Esp))

m5 <- geeglm(
  formula = tim ~ Pa*Pt,
  family = Gamma(link = log),
  data = dat,
  id = Id,
  corstr = "exchangeable"
)
plot_model(m5, type = "pred", terms = c("Pa", "Pt"))


Hope this helps,

Rui Barradas

Às 23:10 de 31/05/21, Luis Fernando García escreveu:

Dear all,

I want to plot a Generalized Estimating Equation (GEE) model, with
interactions  and the confidence interval using a similar style to ggplot2
. I have tried several packages but all of them produce errors. My idea

I wanted to know if anyone knows a graphical package which works with GEE
or simular solution

Dataset in this link:
https://docs.google.com/spreadsheets/d/1nXerN91Iehe9OM1VGDMS3jnbvvF1tWcuS9bGtlrj_Ss/edit?usp=sharing

Thanks!

code below:

library(geepack)
library(ggplot2)
library(visreg)
library(sjPlot)

#Copy dataset before following the code

dat <- read.delim("clipboard", dec=","); attach(dat)
head(dat)
str(dat)
names(dat)
m5<- geeglm(tim~Pa*Pt,id=Esp, Gamma(link=log), corstr="exchangeable")
anova(m5,test="Chisq")
visreg(m5, "Pt", by="Pa",band=T, overlay=TRUE)
plot_model(m5, type = "pred", terms = c("Pa","Pt"))

[[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] Plot with some countries in red

2021-05-19 Thread PIKAL Petr
Hi

For your example

sel <- c(1,4, 9, 11)
text(B, C, A, col=  c("black", "red")[(A %in% A[sel])+1])

gives you required colouring.Not sure if it works with basicPlotteR.

Cheers
Petr

-Original Message-
From: R-help  On Behalf Of varin sacha via R-help
Sent: Wednesday, May 19, 2021 3:14 PM
To: r-help@r-project.org
Subject: [R] Plot with some countries in red

Dear R-experts,

Here below a toy R code example. I would like some countries (not all of them) 
"Italy", "Canada", "Greece" and "Norway" to appear in red color. The others 
remaining black. How can I do that without big changes in my R code ? Indeed, I 
would like my R code to remain like this as much as possible, for example, end 
of my R code, I want to keep the non-overlapping text label.


A<-c("Italy","Germany","USA","Canada","Turkey","Chile","Mexico","Japan","Norway","Finland","Greece")
B<-c(540,523,589,600,499,567,485,467,543,511,500)
C<-c(470,470,489,492,476,475,455,444,489,456,478)

mod1=loess(C~B,span=0.7)
Bfit=seq(from=min(C),to=max(C),length.out=100)
Afit1=predict(mod1,newdata=Bfit)
plot(B,C,main="Courbe de régression non paramétrique entre ISQ 2015 et ISQ 
2018", xlab="score ISQ 2015", ylab="score ISQ 2018 ",type="n")
points(Bfit,Afit1,type="l",lwd=2,col="red")

library(basicPlotteR)
# Add non-overlapping text labels
addTextLabels(B, C, A, col.label="black")








__
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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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 dataframe with color based on a column value

2021-01-24 Thread Luigi Marongiu
I did not know about matplot, but it did the work. using lines is my
default procedure but it can be time-consuming. Thank you all.

On Sun, Jan 24, 2021 at 6:45 PM Rui Barradas  wrote:
>
> Hello,
>
> Base R:
>
> colrs <- rainbow(length(unique(ROI$Z)))
> roi_wide <- reshape(ROI, v.names = "Y", timevar = "Z", idvar = "X",
> direction = "wide")
> matplot(roi_wide, type = "l", lwd = 3, lty = "solid", col = colrs)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 14:48 de 24/01/21, Luigi Marongiu escreveu:
> > Hello
> > is it possible to color the data of a dataframe according to the
> > values of one column?
> > I have a dataframe that OI have subdivided into X and Y, with a third
> > Z with the sample number. I would like to plot Y~X but coloring using
> > Z. But I would like to use base R and not lines.
> > Is that possible?
> > Thank you
> >
> > ```
> > d <- 2
> > K <- 10^13
> > A1_0 <- 1
> > A2_0 <- 100
> > A3_0 <- 500
> > A4_0 <- 1
> > PCR <- function(initCopy, dupRate, Carry) {
> >ROI_T = initCopy
> >A = array()
> >for (i in 1:45) {
> >  ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
> >  A[i] <- ROI_TplusOne
> >  ROI_T <- ROI_TplusOne
> >}
> >return(A)
> > }
> > A1 <- PCR(A1_0, d, K)
> > A2 <- PCR(A2_0, d, K)
> > A3 <- PCR(A3_0, d, K)
> > A4 <- PCR(A4_0, d, K)
> > # store results and plot
> > Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
> > X = rep(1:45,4)
> > Y = c(A1, A2, A3, A4)
> > ROI <- data.frame(Z, X, Y)
> > plot(Y ~ X, data = ROI, type = "l", lwd = 3)
> > ```
> >
> > __
> > 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.
> >



-- 
Best regards,
Luigi

__
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 dataframe with color based on a column value

2021-01-24 Thread Rui Barradas

Hello,

Base R:

colrs <- rainbow(length(unique(ROI$Z)))
roi_wide <- reshape(ROI, v.names = "Y", timevar = "Z", idvar = "X", 
direction = "wide")

matplot(roi_wide, type = "l", lwd = 3, lty = "solid", col = colrs)


Hope this helps,

Rui Barradas

Às 14:48 de 24/01/21, Luigi Marongiu escreveu:

Hello
is it possible to color the data of a dataframe according to the
values of one column?
I have a dataframe that OI have subdivided into X and Y, with a third
Z with the sample number. I would like to plot Y~X but coloring using
Z. But I would like to use base R and not lines.
Is that possible?
Thank you

```
d <- 2
K <- 10^13
A1_0 <- 1
A2_0 <- 100
A3_0 <- 500
A4_0 <- 1
PCR <- function(initCopy, dupRate, Carry) {
   ROI_T = initCopy
   A = array()
   for (i in 1:45) {
 ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
 A[i] <- ROI_TplusOne
 ROI_T <- ROI_TplusOne
   }
   return(A)
}
A1 <- PCR(A1_0, d, K)
A2 <- PCR(A2_0, d, K)
A3 <- PCR(A3_0, d, K)
A4 <- PCR(A4_0, d, K)
# store results and plot
Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
X = rep(1:45,4)
Y = c(A1, A2, A3, A4)
ROI <- data.frame(Z, X, Y)
plot(Y ~ X, data = ROI, type = "l", lwd = 3)
```

__
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 dataframe with color based on a column value

2021-01-24 Thread Bert Gunter
No. I was wrong. ?plot.default says only one line color (the first) will be
used. So it appears that you need to use lines().

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jan 24, 2021 at 8:41 AM Bert Gunter  wrote:

> 1. lines() *is* base R.
>
> 2. See the col argument of ?plot.default.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Jan 24, 2021 at 6:48 AM Luigi Marongiu 
> wrote:
>
>> Hello
>> is it possible to color the data of a dataframe according to the
>> values of one column?
>> I have a dataframe that OI have subdivided into X and Y, with a third
>> Z with the sample number. I would like to plot Y~X but coloring using
>> Z. But I would like to use base R and not lines.
>> Is that possible?
>> Thank you
>>
>> ```
>> d <- 2
>> K <- 10^13
>> A1_0 <- 1
>> A2_0 <- 100
>> A3_0 <- 500
>> A4_0 <- 1
>> PCR <- function(initCopy, dupRate, Carry) {
>>   ROI_T = initCopy
>>   A = array()
>>   for (i in 1:45) {
>> ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
>> A[i] <- ROI_TplusOne
>> ROI_T <- ROI_TplusOne
>>   }
>>   return(A)
>> }
>> A1 <- PCR(A1_0, d, K)
>> A2 <- PCR(A2_0, d, K)
>> A3 <- PCR(A3_0, d, K)
>> A4 <- PCR(A4_0, d, K)
>> # store results and plot
>> Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
>> X = rep(1:45,4)
>> Y = c(A1, A2, A3, A4)
>> ROI <- data.frame(Z, X, Y)
>> plot(Y ~ X, data = ROI, type = "l", lwd = 3)
>> ```
>>
>> __
>> 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] Plot dataframe with color based on a column value

2021-01-24 Thread Bert Gunter
1. lines() *is* base R.

2. See the col argument of ?plot.default.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jan 24, 2021 at 6:48 AM Luigi Marongiu 
wrote:

> Hello
> is it possible to color the data of a dataframe according to the
> values of one column?
> I have a dataframe that OI have subdivided into X and Y, with a third
> Z with the sample number. I would like to plot Y~X but coloring using
> Z. But I would like to use base R and not lines.
> Is that possible?
> Thank you
>
> ```
> d <- 2
> K <- 10^13
> A1_0 <- 1
> A2_0 <- 100
> A3_0 <- 500
> A4_0 <- 1
> PCR <- function(initCopy, dupRate, Carry) {
>   ROI_T = initCopy
>   A = array()
>   for (i in 1:45) {
> ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
> A[i] <- ROI_TplusOne
> ROI_T <- ROI_TplusOne
>   }
>   return(A)
> }
> A1 <- PCR(A1_0, d, K)
> A2 <- PCR(A2_0, d, K)
> A3 <- PCR(A3_0, d, K)
> A4 <- PCR(A4_0, d, K)
> # store results and plot
> Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
> X = rep(1:45,4)
> Y = c(A1, A2, A3, A4)
> ROI <- data.frame(Z, X, Y)
> plot(Y ~ X, data = ROI, type = "l", lwd = 3)
> ```
>
> __
> 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] Plot histogram and lognormal fit on the same time

2021-01-22 Thread Bert Gunter
OK, but that's not the point of my comment.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jan 22, 2021 at 5:03 PM Abby Spurdle  wrote:

> Sorry, Bert.
> The fitdistr function estimates parameters via maximum likelihood.
> (i.e. The "lognormal" part of this, is not a kernel).
>
>
> On Fri, Jan 22, 2021 at 5:14 AM Bert Gunter 
> wrote:
> >
> > In future, you should try to search before posting. I realize that
> getting
> > good search terms can sometimes be tricky, but not in this case: 'plot
> > density with histogram in R' or similar on rseek.org or just on your
> usual
> > search platform brought up several ways to do it.
> >
> > As a (slightly offtopic) side issue, be careful with this: both
> histograms
> > and smooth density estimates are just that: density **estimates** that
> > depend on both the data and various parameters, e.g. the location of the
> > bins for histograms and kernel for kernel density estimates. You may
> > therefore get plots where the two do not appear to "match" when you use
> the
> > defaults for each.
> >
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along
> and
> > sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Thu, Jan 21, 2021 at 3:54 AM Eric Leroy  wrote:
> >
> > > Hi,
> > >
> > > I would like to plot the histogram of data and fit it with a lognormal
> > > distribution.
> > >
> > > The ideal, would be to superimpose the fit on the histogram and write
> > > the results of the fit on the figure.
> > >
> > > Right now, I was able to plot the histogram and fit the density with a
> > > lognormal, but I can't combine all together.
> > >
> > > Here is the code I wrote :
> > >
> > > histdata <- hist(dataframe$data)
> > >
> > > library(MASS)
> > >
> > > fitdistr(histdata$density, "lognormal")
> > >
> > > Can you help me ?
> > >
> > > Best regards,
> > >
> > > --
> > >
> > > *Eric Leroy*
> > >
> > > /Responsable de la plateforme microscopie électronique/
> > >
> > > /Correspondant Sécurité des Systèmes Informatiques de l'ICMPE/
> > >
> > > ICMPE - UMR 7182 - CNRS - UPEC
> > >
> > > 2/8, rue Henri Dunant
> > >
> > > 94320 Thiais
> > >
> > > Tél : 01.49.78.12.09
> > >
> > > Fax : 01.49.78.12.03
> > >
> > > courriel : le...@icmpe.cnrs.fr 
> > >
> > > Page Web : : http://www.icmpe.cnrs.fr 
> > >
> > > __
> > > 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.
>

[[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 histogram and lognormal fit on the same time

2021-01-22 Thread Abby Spurdle
Sorry, Bert.
The fitdistr function estimates parameters via maximum likelihood.
(i.e. The "lognormal" part of this, is not a kernel).


On Fri, Jan 22, 2021 at 5:14 AM Bert Gunter  wrote:
>
> In future, you should try to search before posting. I realize that getting
> good search terms can sometimes be tricky, but not in this case: 'plot
> density with histogram in R' or similar on rseek.org or just on your usual
> search platform brought up several ways to do it.
>
> As a (slightly offtopic) side issue, be careful with this: both histograms
> and smooth density estimates are just that: density **estimates** that
> depend on both the data and various parameters, e.g. the location of the
> bins for histograms and kernel for kernel density estimates. You may
> therefore get plots where the two do not appear to "match" when you use the
> defaults for each.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Jan 21, 2021 at 3:54 AM Eric Leroy  wrote:
>
> > Hi,
> >
> > I would like to plot the histogram of data and fit it with a lognormal
> > distribution.
> >
> > The ideal, would be to superimpose the fit on the histogram and write
> > the results of the fit on the figure.
> >
> > Right now, I was able to plot the histogram and fit the density with a
> > lognormal, but I can't combine all together.
> >
> > Here is the code I wrote :
> >
> > histdata <- hist(dataframe$data)
> >
> > library(MASS)
> >
> > fitdistr(histdata$density, "lognormal")
> >
> > Can you help me ?
> >
> > Best regards,
> >
> > --
> >
> > *Eric Leroy*
> >
> > /Responsable de la plateforme microscopie électronique/
> >
> > /Correspondant Sécurité des Systèmes Informatiques de l'ICMPE/
> >
> > ICMPE - UMR 7182 - CNRS - UPEC
> >
> > 2/8, rue Henri Dunant
> >
> > 94320 Thiais
> >
> > Tél : 01.49.78.12.09
> >
> > Fax : 01.49.78.12.03
> >
> > courriel : le...@icmpe.cnrs.fr 
> >
> > Page Web : : http://www.icmpe.cnrs.fr 
> >
> > __
> > 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-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 histogram and lognormal fit on the same time

2021-01-21 Thread Rui Barradas

Hello,

A solution based on Marc's first one, maybe easier? (It doesn't rely on 
multiplying the dlnorm values by 400 since it plots the histogram with 
freq = FALSE.)



set.seed(2020)
data <- rlnorm(100, meanlog = 1, sdlog = 1)

library(MASS)

f <- fitdistr(data, "lognormal")
f$estimate

p <- pretty(range(data))
x <- seq(from = min(p), to = max(p), by = 0.1)

hist(data, freq = FALSE)
lines(x, y = dlnorm(x,
meanlog = f$estimate["meanlog"],
sdlog = f$estimate["sdlog"])
)


Hope this helps,

Rui Barradas


Às 13:12 de 21/01/21, Marc Girondot via R-help escreveu:

Two solutions not exactly equivalent ;

data <- rlnorm(100, meanlog = 1, sdlog = 1)
histdata <- hist(data, ylim=c(0, 100))
library(MASS)

f <- fitdistr(data, "lognormal")

f$estimate

lines(x=seq(from=0, to=50, by=0.1),
  � y=dlnorm(x=seq(from=0, to=50, by=0.1), meanlog =
f$estimate["meanlog"], sdlog = f$estimate["sdlog"])*400
)

library(HelpersMG)

m <- modeled.hist(breaks=histdata$breaks, FUN=plnorm,
  � meanlog = f$estimate["meanlog"], sdlog =
f$estimate["sdlog"], sum = 100)

points(m$x, m$y, pch=19, col="red")

Marc Girondot

Le 21/01/2021 � 12:54, Eric Leroy a �crit�:

Hi,

I would like to plot the histogram of data and fit it with a lognormal
distribution.

The ideal, would be to superimpose the fit on the histogram and write
the results of the fit on the figure.

Right now, I was able to plot the histogram and fit the density with a
lognormal, but I can't combine all together.

Here is the code I wrote :

histdata <- hist(dataframe$data)

library(MASS)

fitdistr(histdata$density, "lognormal")

Can you help me ?

Best regards,


__
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-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 histogram and lognormal fit on the same time

2021-01-21 Thread Bert Gunter
In future, you should try to search before posting. I realize that getting
good search terms can sometimes be tricky, but not in this case: 'plot
density with histogram in R' or similar on rseek.org or just on your usual
search platform brought up several ways to do it.

As a (slightly offtopic) side issue, be careful with this: both histograms
and smooth density estimates are just that: density **estimates** that
depend on both the data and various parameters, e.g. the location of the
bins for histograms and kernel for kernel density estimates. You may
therefore get plots where the two do not appear to "match" when you use the
defaults for each.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jan 21, 2021 at 3:54 AM Eric Leroy  wrote:

> Hi,
>
> I would like to plot the histogram of data and fit it with a lognormal
> distribution.
>
> The ideal, would be to superimpose the fit on the histogram and write
> the results of the fit on the figure.
>
> Right now, I was able to plot the histogram and fit the density with a
> lognormal, but I can't combine all together.
>
> Here is the code I wrote :
>
> histdata <- hist(dataframe$data)
>
> library(MASS)
>
> fitdistr(histdata$density, "lognormal")
>
> Can you help me ?
>
> Best regards,
>
> --
>
> *Eric Leroy*
>
> /Responsable de la plateforme microscopie électronique/
>
> /Correspondant Sécurité des Systèmes Informatiques de l'ICMPE/
>
> ICMPE - UMR 7182 - CNRS - UPEC
>
> 2/8, rue Henri Dunant
>
> 94320 Thiais
>
> Tél : 01.49.78.12.09
>
> Fax : 01.49.78.12.03
>
> courriel : le...@icmpe.cnrs.fr 
>
> Page Web : : http://www.icmpe.cnrs.fr 
>
> __
> 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] Plot histogram and lognormal fit on the same time

2021-01-21 Thread Marc Girondot via R-help
Two solutions not exactly equivalent ;

data <- rlnorm(100, meanlog = 1, sdlog = 1)
histdata <- hist(data, ylim=c(0, 100))
library(MASS)

f <- fitdistr(data, "lognormal")

f$estimate

lines(x=seq(from=0, to=50, by=0.1),
 � y=dlnorm(x=seq(from=0, to=50, by=0.1), meanlog = 
f$estimate["meanlog"], sdlog = f$estimate["sdlog"])*400
)

library(HelpersMG)

m <- modeled.hist(breaks=histdata$breaks, FUN=plnorm,
 � meanlog = f$estimate["meanlog"], sdlog = 
f$estimate["sdlog"], sum = 100)

points(m$x, m$y, pch=19, col="red")

Marc Girondot

Le 21/01/2021 � 12:54, Eric Leroy a �crit�:
> Hi,
>
> I would like to plot the histogram of data and fit it with a lognormal 
> distribution.
>
> The ideal, would be to superimpose the fit on the histogram and write 
> the results of the fit on the figure.
>
> Right now, I was able to plot the histogram and fit the density with a 
> lognormal, but I can't combine all together.
>
> Here is the code I wrote :
>
> histdata <- hist(dataframe$data)
>
> library(MASS)
>
> fitdistr(histdata$density, "lognormal")
>
> Can you help me ?
>
> Best regards,
>
>
> __
> 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] plot factors with dots in R

2020-08-31 Thread Luigi Marongiu
Thank you, all solutions work!

On Fri, Aug 28, 2020 at 9:02 AM Deepayan Sarkar
 wrote:
>
> On Thu, Aug 27, 2020 at 5:46 PM Luigi Marongiu  
> wrote:
> >
> > Hello,
> > I have a dataframe as follows:
> > ```
> > x = c("0 pmol", "10 pmol", "100 pmol", "1000 pmol")
> > y = c(0.9306, 1.8906, 2.2396, 2.7917)
> > df = data.frame(x, y)
> >
> > > str(df)
> > 'data.frame': 4 obs. of  2 variables:
> >  $ x: chr  "0 pmol" "10 pmol" "100 pmol" "1000 pmol"
> >  $ y: num  0.931 1.891 2.24 2.792
> > ```
> > I would like to visualize the data with the classic dots (pch=16) but:
>
> Perhaps this is a good starting point:
>
> with(df, dotchart(y, labels = x, pch = 16))
>
> -Deepayan
>
> > ```
> > > plot(df$y ~ df$x)
> > Error in plot.window(...) : need finite 'xlim' values
> > In addition: Warning messages:
> > 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> > 2: In min(x) : no non-missing arguments to min; returning Inf
> > 3: In max(x) : no non-missing arguments to max; returning -Inf
> > ```
> > which is right because x is not numeric, so I took the factor:
> > ```
> > plot(df$y ~ factor(df$x)) # gives bars instead of dots
> > plot(df$y ~ factor(df$x), pch = 16) # this also
> > ```
> > I tried to convert directly the dataframe:
> > ```
> > df$x = lapply(df$x, factor)
> > > str(df)
> > 'data.frame': 4 obs. of  2 variables:
> >  $ x:List of 4
> >   ..$ : Factor w/ 1 level "0 pmol": 1
> >   ..$ : Factor w/ 1 level "10 pmol": 1
> >   ..$ : Factor w/ 1 level "100 pmol": 1
> >   ..$ : Factor w/ 1 level "1000 pmol": 1
> >  $ y: num  0.931 1.891 2.24 2.792
> >
> > > plot(r$y ~ r$x, pch = 16)
> > Error in plot.window(...) : need finite 'xlim' values
> > In addition: Warning messages:
> > 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> > 2: In min(x) : no non-missing arguments to min; returning Inf
> > 3: In max(x) : no non-missing arguments to max; returning -Inf
> > ```
> > If I try to pass the number of levels:
> > ```
> > plot(df$y ~ factor(df$x, 1:4), pch = 16) # this draw a boxplot with
> > all data on level 1
> >
> > > df$x = lapply(df$x, factor(1:4))
> > Error in match.fun(FUN) :
> >   'factor(1:4)' is not a function, character or symbol
> > ```
> >
> > Since the transformation has given only one level (1), my questions are:
> > How do I tell R to use a dot instead of a line?
> > What is the correct way of setting factors?
> >
> >
> > --
> > Best regards,
> > Luigi
> >
> > __
> > 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.



-- 
Best regards,
Luigi

__
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 factors with dots in R

2020-08-28 Thread Deepayan Sarkar
On Thu, Aug 27, 2020 at 5:46 PM Luigi Marongiu  wrote:
>
> Hello,
> I have a dataframe as follows:
> ```
> x = c("0 pmol", "10 pmol", "100 pmol", "1000 pmol")
> y = c(0.9306, 1.8906, 2.2396, 2.7917)
> df = data.frame(x, y)
>
> > str(df)
> 'data.frame': 4 obs. of  2 variables:
>  $ x: chr  "0 pmol" "10 pmol" "100 pmol" "1000 pmol"
>  $ y: num  0.931 1.891 2.24 2.792
> ```
> I would like to visualize the data with the classic dots (pch=16) but:

Perhaps this is a good starting point:

with(df, dotchart(y, labels = x, pch = 16))

-Deepayan

> ```
> > plot(df$y ~ df$x)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> ```
> which is right because x is not numeric, so I took the factor:
> ```
> plot(df$y ~ factor(df$x)) # gives bars instead of dots
> plot(df$y ~ factor(df$x), pch = 16) # this also
> ```
> I tried to convert directly the dataframe:
> ```
> df$x = lapply(df$x, factor)
> > str(df)
> 'data.frame': 4 obs. of  2 variables:
>  $ x:List of 4
>   ..$ : Factor w/ 1 level "0 pmol": 1
>   ..$ : Factor w/ 1 level "10 pmol": 1
>   ..$ : Factor w/ 1 level "100 pmol": 1
>   ..$ : Factor w/ 1 level "1000 pmol": 1
>  $ y: num  0.931 1.891 2.24 2.792
>
> > plot(r$y ~ r$x, pch = 16)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> ```
> If I try to pass the number of levels:
> ```
> plot(df$y ~ factor(df$x, 1:4), pch = 16) # this draw a boxplot with
> all data on level 1
>
> > df$x = lapply(df$x, factor(1:4))
> Error in match.fun(FUN) :
>   'factor(1:4)' is not a function, character or symbol
> ```
>
> Since the transformation has given only one level (1), my questions are:
> How do I tell R to use a dot instead of a line?
> What is the correct way of setting factors?
>
>
> --
> Best regards,
> Luigi
>
> __
> 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 factors with dots in R

2020-08-27 Thread Jim Lemon
Hi Luigi,
Maybe just:

plot(as.numeric(factor(x,levels=x)),y,xaxt="n",
 main="Concentration by effect",
 xlab="Concentration",ylab="Effect")
axis(1,at=1:4,labels=x)

Jim

On Thu, Aug 27, 2020 at 10:16 PM Luigi Marongiu
 wrote:
>
> Hello,
> I have a dataframe as follows:
> ```
> x = c("0 pmol", "10 pmol", "100 pmol", "1000 pmol")
> y = c(0.9306, 1.8906, 2.2396, 2.7917)
> df = data.frame(x, y)
>
> > str(df)
> 'data.frame': 4 obs. of  2 variables:
>  $ x: chr  "0 pmol" "10 pmol" "100 pmol" "1000 pmol"
>  $ y: num  0.931 1.891 2.24 2.792
> ```
> I would like to visualize the data with the classic dots (pch=16) but:
> ```
> > plot(df$y ~ df$x)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> ```
> which is right because x is not numeric, so I took the factor:
> ```
> plot(df$y ~ factor(df$x)) # gives bars instead of dots
> plot(df$y ~ factor(df$x), pch = 16) # this also
> ```
> I tried to convert directly the dataframe:
> ```
> df$x = lapply(df$x, factor)
> > str(df)
> 'data.frame': 4 obs. of  2 variables:
>  $ x:List of 4
>   ..$ : Factor w/ 1 level "0 pmol": 1
>   ..$ : Factor w/ 1 level "10 pmol": 1
>   ..$ : Factor w/ 1 level "100 pmol": 1
>   ..$ : Factor w/ 1 level "1000 pmol": 1
>  $ y: num  0.931 1.891 2.24 2.792
>
> > plot(r$y ~ r$x, pch = 16)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> ```
> If I try to pass the number of levels:
> ```
> plot(df$y ~ factor(df$x, 1:4), pch = 16) # this draw a boxplot with
> all data on level 1
>
> > df$x = lapply(df$x, factor(1:4))
> Error in match.fun(FUN) :
>   'factor(1:4)' is not a function, character or symbol
> ```
>
> Since the transformation has given only one level (1), my questions are:
> How do I tell R to use a dot instead of a line?
> What is the correct way of setting factors?
>
>
> --
> Best regards,
> Luigi
>
> __
> 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 factors with dots in R

2020-08-27 Thread Rui Barradas

Hello,

The plots that you say give bars (or my equivalent version below) don't 
give bars, what they give are boxplots with just one value and the 
median Q1 and Q3 are all equal.


plot(y ~ factor(x), df, pch = 16)  # boxplot


Is the following what you are looking for?


plot(y ~ as.integer(factor(x)), df, pch = 16, xlab = "x", xaxt = "n")
axis(1, at = as.integer(factor(df$x)), labels = df$x)


Hope this helps,

Rui Barradas


Às 13:16 de 27/08/20, Luigi Marongiu escreveu:

Hello,
I have a dataframe as follows:
```
x = c("0 pmol", "10 pmol", "100 pmol", "1000 pmol")
y = c(0.9306, 1.8906, 2.2396, 2.7917)
df = data.frame(x, y)


str(df)

'data.frame': 4 obs. of  2 variables:
  $ x: chr  "0 pmol" "10 pmol" "100 pmol" "1000 pmol"
  $ y: num  0.931 1.891 2.24 2.792
```
I would like to visualize the data with the classic dots (pch=16) but:
```

plot(df$y ~ df$x)

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
```
which is right because x is not numeric, so I took the factor:
```
plot(df$y ~ factor(df$x)) # gives bars instead of dots
plot(df$y ~ factor(df$x), pch = 16) # this also
```
I tried to convert directly the dataframe:
```
df$x = lapply(df$x, factor)

str(df)

'data.frame': 4 obs. of  2 variables:
  $ x:List of 4
   ..$ : Factor w/ 1 level "0 pmol": 1
   ..$ : Factor w/ 1 level "10 pmol": 1
   ..$ : Factor w/ 1 level "100 pmol": 1
   ..$ : Factor w/ 1 level "1000 pmol": 1
  $ y: num  0.931 1.891 2.24 2.792


plot(r$y ~ r$x, pch = 16)

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
```
If I try to pass the number of levels:
```
plot(df$y ~ factor(df$x, 1:4), pch = 16) # this draw a boxplot with
all data on level 1


df$x = lapply(df$x, factor(1:4))

Error in match.fun(FUN) :
   'factor(1:4)' is not a function, character or symbol
```

Since the transformation has given only one level (1), my questions are:
How do I tell R to use a dot instead of a line?
What is the correct way of setting factors?




__
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 factors with dots in R

2020-08-27 Thread Luigi Marongiu
Thank you, better than before...

On Thu, Aug 27, 2020 at 2:37 PM PIKAL Petr  wrote:
>
> Hi.
> It is probably somewhere in docs, but factors are actually numerics vith
> labels.
>
> So with your original data frame
>
> df$x <- factor(df$x)
> plot(as.numeric(df$x), df$y)
>
> gives you points. You need to set labels to x axis though.
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help  On Behalf Of Luigi Marongiu
> > Sent: Thursday, August 27, 2020 2:16 PM
> > To: r-help 
> > Subject: [R] plot factors with dots in R
> >
> > Hello,
> > I have a dataframe as follows:
> > ```
> > x = c("0 pmol", "10 pmol", "100 pmol", "1000 pmol")
> > y = c(0.9306, 1.8906, 2.2396, 2.7917)
> > df = data.frame(x, y)
> >
> > > str(df)
> > 'data.frame': 4 obs. of  2 variables:
> >  $ x: chr  "0 pmol" "10 pmol" "100 pmol" "1000 pmol"
> >  $ y: num  0.931 1.891 2.24 2.792
> > ```
> > I would like to visualize the data with the classic dots (pch=16) but:
> > ```
> > > plot(df$y ~ df$x)
> > Error in plot.window(...) : need finite 'xlim' values
> > In addition: Warning messages:
> > 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> > 2: In min(x) : no non-missing arguments to min; returning Inf
> > 3: In max(x) : no non-missing arguments to max; returning -Inf
> > ```
> > which is right because x is not numeric, so I took the factor:
> > ```
> > plot(df$y ~ factor(df$x)) # gives bars instead of dots
> > plot(df$y ~ factor(df$x), pch = 16) # this also
> > ```
> > I tried to convert directly the dataframe:
> > ```
> > df$x = lapply(df$x, factor)
> > > str(df)
> > 'data.frame': 4 obs. of  2 variables:
> >  $ x:List of 4
> >   ..$ : Factor w/ 1 level "0 pmol": 1
> >   ..$ : Factor w/ 1 level "10 pmol": 1
> >   ..$ : Factor w/ 1 level "100 pmol": 1
> >   ..$ : Factor w/ 1 level "1000 pmol": 1
> >  $ y: num  0.931 1.891 2.24 2.792
> >
> > > plot(r$y ~ r$x, pch = 16)
> > Error in plot.window(...) : need finite 'xlim' values
> > In addition: Warning messages:
> > 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> > 2: In min(x) : no non-missing arguments to min; returning Inf
> > 3: In max(x) : no non-missing arguments to max; returning -Inf
> > ```
> > If I try to pass the number of levels:
> > ```
> > plot(df$y ~ factor(df$x, 1:4), pch = 16) # this draw a boxplot with
> > all data on level 1
> >
> > > df$x = lapply(df$x, factor(1:4))
> > Error in match.fun(FUN) :
> >   'factor(1:4)' is not a function, character or symbol
> > ```
> >
> > Since the transformation has given only one level (1), my questions are:
> > How do I tell R to use a dot instead of a line?
> > What is the correct way of setting factors?
> >
> >
> > --
> > Best regards,
> > Luigi
> >
> > __
> > 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.



-- 
Best regards,
Luigi

__
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 factors with dots in R

2020-08-27 Thread PIKAL Petr
Hi.
It is probably somewhere in docs, but factors are actually numerics vith
labels. 

So with your original data frame

df$x <- factor(df$x)
plot(as.numeric(df$x), df$y)

gives you points. You need to set labels to x axis though.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Luigi Marongiu
> Sent: Thursday, August 27, 2020 2:16 PM
> To: r-help 
> Subject: [R] plot factors with dots in R
> 
> Hello,
> I have a dataframe as follows:
> ```
> x = c("0 pmol", "10 pmol", "100 pmol", "1000 pmol")
> y = c(0.9306, 1.8906, 2.2396, 2.7917)
> df = data.frame(x, y)
> 
> > str(df)
> 'data.frame': 4 obs. of  2 variables:
>  $ x: chr  "0 pmol" "10 pmol" "100 pmol" "1000 pmol"
>  $ y: num  0.931 1.891 2.24 2.792
> ```
> I would like to visualize the data with the classic dots (pch=16) but:
> ```
> > plot(df$y ~ df$x)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> ```
> which is right because x is not numeric, so I took the factor:
> ```
> plot(df$y ~ factor(df$x)) # gives bars instead of dots
> plot(df$y ~ factor(df$x), pch = 16) # this also
> ```
> I tried to convert directly the dataframe:
> ```
> df$x = lapply(df$x, factor)
> > str(df)
> 'data.frame': 4 obs. of  2 variables:
>  $ x:List of 4
>   ..$ : Factor w/ 1 level "0 pmol": 1
>   ..$ : Factor w/ 1 level "10 pmol": 1
>   ..$ : Factor w/ 1 level "100 pmol": 1
>   ..$ : Factor w/ 1 level "1000 pmol": 1
>  $ y: num  0.931 1.891 2.24 2.792
> 
> > plot(r$y ~ r$x, pch = 16)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> ```
> If I try to pass the number of levels:
> ```
> plot(df$y ~ factor(df$x, 1:4), pch = 16) # this draw a boxplot with
> all data on level 1
> 
> > df$x = lapply(df$x, factor(1:4))
> Error in match.fun(FUN) :
>   'factor(1:4)' is not a function, character or symbol
> ```
> 
> Since the transformation has given only one level (1), my questions are:
> How do I tell R to use a dot instead of a line?
> What is the correct way of setting factors?
> 
> 
> --
> Best regards,
> Luigi
> 
> __
> 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 math symbol with string and number

2020-08-18 Thread Rasmus Liland
On 2020-08-18 11:02 +1200, Paul Murrell wrote:
| On 18/08/20 9:54 am, Bert Gunter wrote:
| | On Mon, Aug 17, 2020 at 2:14 PM  wrote:
| | | 
| | | Plotmath seems to be the right way 
| | | to do it.  But without reading 
| | | plotmath I'd have gone with this:
| | | 
| | | plot(y, main=paste("data", "\u03C3=", s))
| | 
| | "Plotmath seems to be the right way 
| | to do it."
| | 
| | Not sure I agree with that. Paul 
| | Murrell put together plotmath around 
| | 2000 prior to the widescale 
| | development and adoption of the 
| | unicode standard 
| | (corrections/modifications 
| | welcome!).  So at the time, there 
| | really was no other way to handle 
| | this for most OS'es. With UTF8 now 
| | being generally supported for 
| | Unicode, plotmath constructions may 
| | not be needed for simple symbol 
| | labeling, as here. Of course for 
| | more complex symbolism (fractions, 
| | integrals, ...) it will be. 
| | ?plotmath talks about this and has 
| | links to further issues and options, 
| | btw.
| | 
| | In other words, unicode may indeed 
| | be better than my suggestion of 
| | plotmath here.
| 
| I think that comment is fair *on 
| graphics devices that can handle 
| unicode*.
| 
| So that is true for Cairo-based 
| graphics devices, but not for the 
| pdf() or postscript() devices, for 
| example.

Eventhough I'm a heavy user of pdf(), I 
didn't notice at first that the sigma 
gets converted to two dots with the 
error messages

Warning messages:
1: In title(...) :
  conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted 
for 
2: In title(...) :
  conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted 
for <83>
3: In title(...) :
  conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted 
for 
4: In title(...) :
  conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted 
for <83>

like if it was a Han character (most 
likely three dots in that case), I just 
ran with cpolwart's suggestion in 
whatever is the default on the R 
console, probably that Cairo thing.  
png() works ofc. 

V

r


signature.asc
Description: PGP signature
__
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 math symbol with string and number

2020-08-17 Thread Paul Murrell



I think that comment is fair *on graphics devices that can handle unicode*.

So that is true for Cairo-based graphics devices, but not for the pdf() 
or postscript() devices, for example.


Paul

On 18/08/20 9:54 am, Bert Gunter wrote:

"Plotmath seems to be the right way to do it."

Not sure I agree with that. Paul Murrell put together plotmath around 2000
prior to the widescale development and adoption of the unicode standard
(corrections/modifications welcome!).  So at the time, there really was no
other way to handle this for most OS'es. With UTF8 now being generally
supported for Unicode, plotmath constructions may not be needed for simple
symbol labeling, as here. Of course for more complex symbolism (fractions,
integrals, ...) it will be. ?plotmath talks about this and has links to
further issues and options, btw.

In other words, unicode may indeed be better than my suggestion of plotmath
here.

I would welcome comments from others who are more knowledgeable about this
than I am.

Bert

On Mon, Aug 17, 2020 at 2:14 PM  wrote:


On 2020-08-17 03:13, Rasmus Liland wrote:

On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
| On Sun, Aug 16, 2020, 14:53 John wrote:
| |
| | I would like to make plots with
| | titles for different data sets and
| | different parameters. The first
| | title doesn't show sigma as a math
| | symbol, while the second one
| | doesn't contain the s value as a
| | numeric value
| |
| | s <- 1
| | y <- rnorm(100)
| | plot(y, main=paste("data", "sigma=", s))
| | plot(y, main=expression(paste("data", sigma,"=", s)))
|
| ?plotmath

Dear John, read ?plotmath, it is good, I
was not aware of its existence; then
backquote s like so:




Plotmath seems to be the right way to do it.  But without reading
plotmath I'd have gone with this:

plot(y, main=paste("data", "\u03C3=", s))






[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=02%7C01%7C%7C3624d54caaf64787734308d842f83677%7Cd1b36e950d5042e9958fb63fa906beaa%7C0%7C0%7C637332981200092221sdata=U7ywrEh7Z3XV84pkxXfzUJTYU8BEZ995Np5xo3%2Fbn9g%3Dreserved=0
PLEASE do read the posting guide 
https://apc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=02%7C01%7C%7C3624d54caaf64787734308d842f83677%7Cd1b36e950d5042e9958fb63fa906beaa%7C0%7C0%7C637332981200092221sdata=7VBd7dQFox%2BCEUEKgJZk6TU6cwmDS7tnAcGok9UH1WQ%3Dreserved=0
and provide commented, minimal, self-contained, reproducible code.



--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

__
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 math symbol with string and number

2020-08-17 Thread Bert Gunter
"Plotmath seems to be the right way to do it. "

Not sure I agree with that. Paul Murrell put together plotmath around 2000
prior to the widescale development and adoption of the unicode standard
(corrections/modifications welcome!).  So at the time, there really was no
other way to handle this for most OS'es. With UTF8 now being generally
supported for Unicode, plotmath constructions may not be needed for simple
symbol labeling, as here. Of course for more complex symbolism (fractions,
integrals, ...) it will be. ?plotmath talks about this and has links to
further issues and options, btw.

In other words, unicode may indeed be better than my suggestion of plotmath
here.

I would welcome comments from others who are more knowledgeable about this
than I am.

Bert

On Mon, Aug 17, 2020 at 2:14 PM  wrote:

> On 2020-08-17 03:13, Rasmus Liland wrote:
> > On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
> > | On Sun, Aug 16, 2020, 14:53 John wrote:
> > | |
> > | | I would like to make plots with
> > | | titles for different data sets and
> > | | different parameters. The first
> > | | title doesn't show sigma as a math
> > | | symbol, while the second one
> > | | doesn't contain the s value as a
> > | | numeric value
> > | |
> > | | s <- 1
> > | | y <- rnorm(100)
> > | | plot(y, main=paste("data", "sigma=", s))
> > | | plot(y, main=expression(paste("data", sigma,"=", s)))
> > |
> > | ?plotmath
> >
> > Dear John, read ?plotmath, it is good, I
> > was not aware of its existence; then
> > backquote s like so:
> >
> >
>
> Plotmath seems to be the right way to do it.  But without reading
> plotmath I'd have gone with this:
>
> plot(y, main=paste("data", "\u03C3=", s))
>
>
>
>

[[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 math symbol with string and number

2020-08-17 Thread Rasmus Liland
On 2020-08-17 22:14 +0100, cpolw...@chemo.org.uk wrote:
| On 2020-08-17 03:13, Rasmus Liland wrote:
| | On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
| | |
| | | ?plotmath
| | 
| | Dear John, read ?plotmath, it is 
| | good, I was not aware of its 
| | existence; then backquote s like 
| | so:
| 
| Plotmath seems to be the right way to 
| do it.  But without reading plotmath 
| I'd have gone with this:
| 
| plot(y, main=paste("data", "\u03C3=", s))

Good; for me copying the sigma unicode 
character into that line works too:

plot(y, main=paste("dataσ=", s))

How curious 


signature.asc
Description: PGP signature
__
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 math symbol with string and number

2020-08-17 Thread cpolwart

On 2020-08-17 03:13, Rasmus Liland wrote:

On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
| On Sun, Aug 16, 2020, 14:53 John wrote:
| |
| | I would like to make plots with
| | titles for different data sets and
| | different parameters. The first
| | title doesn't show sigma as a math
| | symbol, while the second one
| | doesn't contain the s value as a
| | numeric value
| |
| | s <- 1
| | y <- rnorm(100)
| | plot(y, main=paste("data", "sigma=", s))
| | plot(y, main=expression(paste("data", sigma,"=", s)))
|
| ?plotmath

Dear John, read ?plotmath, it is good, I
was not aware of its existence; then
backquote s like so:




Plotmath seems to be the right way to do it.  But without reading 
plotmath I'd have gone with this:


plot(y, main=paste("data", "\u03C3=", s))

__
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 math symbol with string and number

2020-08-17 Thread John Smith
Thanks to Dunkan, Rasmus and Bert. Will keep the very useful tips. Best!

On Sun, Aug 16, 2020 at 9:13 PM Rasmus Liland  wrote:

> On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
> | On Sun, Aug 16, 2020, 14:53 John wrote:
> | |
> | | I would like to make plots with
> | | titles for different data sets and
> | | different parameters. The first
> | | title doesn't show sigma as a math
> | | symbol, while the second one
> | | doesn't contain the s value as a
> | | numeric value
> | |
> | | s <- 1
> | | y <- rnorm(100)
> | | plot(y, main=paste("data", "sigma=", s))
> | | plot(y, main=expression(paste("data", sigma,"=", s)))
> |
> | ?plotmath
>
> Dear John, read ?plotmath, it is good, I
> was not aware of its existence; then
> backquote s like so:
>
> plot(y, main=bquote(paste(
>   "data" ~~ widehat(aleph)
>   %notin% .(s)^.(s
>
> V
>
> r
>

[[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 math symbol with string and number

2020-08-16 Thread Rasmus Liland
On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
| On Sun, Aug 16, 2020, 14:53 John wrote:
| | 
| | I would like to make plots with 
| | titles for different data sets and 
| | different parameters. The first 
| | title doesn't show sigma as a math 
| | symbol, while the second one 
| | doesn't contain the s value as a 
| | numeric value
| |
| | s <- 1
| | y <- rnorm(100)
| | plot(y, main=paste("data", "sigma=", s))
| | plot(y, main=expression(paste("data", sigma,"=", s)))
|
| ?plotmath

Dear John, read ?plotmath, it is good, I 
was not aware of its existence; then 
backquote s like so:

plot(y, main=bquote(paste(
  "data" ~~ widehat(aleph) 
  %notin% .(s)^.(s

V

r

__
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 math symbol with string and number

2020-08-16 Thread Bert Gunter
Specifically, see the "how to combine "math" and numeric variables" in the
Examples therein.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Aug 16, 2020 at 3:18 PM Bert Gunter  wrote:

> ?plotmath
>
> On Sun, Aug 16, 2020, 14:53 John Smith  wrote:
>
>> Dear Helpers,
>>
>> I would like to make plots with titles for different data sets and
>> different parameters. So a useful title should combine data name
>> and parameter for clarity. The following is a simplified code example with
>> two plots. The first title doesn't show sigma as a math symbol, while the
>> second one doesn't contain the s value as a numeric value - I could
>> manually change the s value, but when there are many different s values,
>> this is not a good solution. Thanks!
>>
>> s <- 1
>> y <- rnorm(100)
>> plot(y, main=paste("data", "sigma=", s))
>> plot(y, main=expression(paste("data", sigma,"=", s)))
>>
>> [[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.


Re: [R] Plot math symbol with string and number

2020-08-16 Thread Bert Gunter
?plotmath

On Sun, Aug 16, 2020, 14:53 John Smith  wrote:

> Dear Helpers,
>
> I would like to make plots with titles for different data sets and
> different parameters. So a useful title should combine data name
> and parameter for clarity. The following is a simplified code example with
> two plots. The first title doesn't show sigma as a math symbol, while the
> second one doesn't contain the s value as a numeric value - I could
> manually change the s value, but when there are many different s values,
> this is not a good solution. Thanks!
>
> s <- 1
> y <- rnorm(100)
> plot(y, main=paste("data", "sigma=", s))
> plot(y, main=expression(paste("data", sigma,"=", s)))
>
> [[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.


Re: [R] Plot base 100

2020-07-20 Thread Joshua Ulrich
You can do this with PerformanceAnalytics.

library(PerformanceAnalytics)
data(edhec)
chart.RelativePerformance(edhec, 0, legend = "topleft")

Also note that there's a finance-specific mailing list: R-SIG-Finance.

Best,
Josh

On Sun, Jul 19, 2020 at 1:46 PM Pedro páramo  wrote:
>
> Hi all,
>
> I am trying to make a plot based on stock market prices and the library
> quantmod, imagine
>
> BatchGetSymbols(‘^IBEX’, first.date = ‘1999-12-31’,
>  last.date = ‘2020-12-07’)
>
> The thing is I want to plot a plot that for each year on 31/12/year tthe
> base is 100 and each day calvulate the cumulative returns so if on
> 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to
> plot for each day off the year to the end of the year a line (in fact would
> be 20 lines) in the example from year 2000 to actual 2020.
>
> Aditionally on the current year I want to plot the line more thig (dar) to
> clearly distinguish It.
>
> Do you know if there is some predefinited function to construct It.
>
> Many thanks in advance
>
> [[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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.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] Plot base 100

2020-07-20 Thread Pedro páramo
I understand. I Will send my Code tomorrow, I am outside home now.

Many thanks David, sorry about all.

El dom., 19 jul. 2020 21:13, David Winsemius 
escribió:

>
> On 7/19/20 11:18 AM, Pedro páramo wrote:
> > Hi all,
> >
> > I am trying to make a plot based on stock market prices and the library
> > quantmod, imagine
> >
> > BatchGetSymbols(‘^IBEX’, first.date = ‘1999-12-31’,
> >   last.date = ‘2020-12-07’)
> >
> > The thing is I want to plot a plot that for each year on 31/12/year tthe
> > base is 100 and each day calvulate the cumulative returns so if on
> > 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want
> to
> > plot for each day off the year to the end of the year a line (in fact
> would
> > be 20 lines) in the example from year 2000 to actual 2020.
> >
> > Aditionally on the current year I want to plot the line more thig (dar)
> to
> > clearly distinguish It.
> >
> > Do you know if there is some predefinited function to construct It.
> >
> > Many thanks in advance
> >
> >   [[alternative HTML version deleted]]
>
>
> Rhelp is a plain text mailing list. It is not a project server. We don't
> exist to deliver code on command. We do exist to help with efforts at R
> coding. First you need to use an editor that does not create "smart
> quotes" by default. You should also start your code with library calls
> to load all necessary packages. I note this because GetBatchSymbols is
> not in package:quantmod. You should then show all the code from your
> efforts at investigation of objects' structure and properties and your
> efforts at plotting. Then describe what sort of problems you seem to be
> having in understanding the results and modifying them.
>
>
> --
>
> David
>
> >
> > __
> > 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] Plot base 100

2020-07-19 Thread Jim Lemon
Hi Pedro,
Assuming that you get a vector of daily percentage changes:

dpc<-c(+3.1, -2.8, +1.7, +2.1)

get the cumulative change and add 100:

cumsum(dpc)+100
[1] 103.1 100.3 102.0 104.1

You can then plot that. As Rui noted, your mail client is inserting
invisible characters that prevent cutting and pasting into R.

Jim

On Mon, Jul 20, 2020 at 4:46 AM Pedro páramo  wrote:
>
> Hi all,
>
> I am trying to make a plot based on stock market prices and the library
> quantmod, imagine
>
> BatchGetSymbols(‘^IBEX’, first.date = ‘1999-12-31’,
>  last.date = ‘2020-12-07’)
>
> The thing is I want to plot a plot that for each year on 31/12/year tthe
> base is 100 and each day calvulate the cumulative returns so if on
> 01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to
> plot for each day off the year to the end of the year a line (in fact would
> be 20 lines) in the example from year 2000 to actual 2020.
>
> Aditionally on the current year I want to plot the line more thig (dar) to
> clearly distinguish It.
>
> Do you know if there is some predefinited function to construct It.
>
> Many thanks in advance
>
> [[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] Plot base 100

2020-07-19 Thread David Winsemius



On 7/19/20 11:18 AM, Pedro páramo wrote:

Hi all,

I am trying to make a plot based on stock market prices and the library
quantmod, imagine

BatchGetSymbols(‘^IBEX’, first.date = ‘1999-12-31’,
  last.date = ‘2020-12-07’)

The thing is I want to plot a plot that for each year on 31/12/year tthe
base is 100 and each day calvulate the cumulative returns so if on
01/01/year t+1 in one day stock climbs a 3% the Index values 103. I want to
plot for each day off the year to the end of the year a line (in fact would
be 20 lines) in the example from year 2000 to actual 2020.

Aditionally on the current year I want to plot the line more thig (dar) to
clearly distinguish It.

Do you know if there is some predefinited function to construct It.

Many thanks in advance

[[alternative HTML version deleted]]



Rhelp is a plain text mailing list. It is not a project server. We don't 
exist to deliver code on command. We do exist to help with efforts at R 
coding. First you need to use an editor that does not create "smart 
quotes" by default. You should also start your code with library calls 
to load all necessary packages. I note this because GetBatchSymbols is 
not in package:quantmod. You should then show all the code from your 
efforts at investigation of objects' structure and properties and your 
efforts at plotting. Then describe what sort of problems you seem to be 
having in understanding the results and modifying them.



--

David



__
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 shows exponential values incompatible with data

2020-07-10 Thread Fox, John
Dear Jim,

As I pointed out yesterday, setting ylim as you suggest still results in 
"0e+00" as the smallest tick mark, as it should for evenly spaced ticks. 

Best,
 John

> On Jul 10, 2020, at 12:13 AM, Jim Lemon  wrote:
> 
> Hi Luigi,
> This is a result of the "pretty" function that calculates hopefully
> good looking axis ticks automatically. You can always specify
> ylim=c(1.0E09,max(Y)) if you want.
> 
> Jim
> 
> On Thu, Jul 9, 2020 at 10:59 PM Luigi Marongiu  
> wrote:
>> 
>> Hello,
>> I have these vectors:
>> ```
>> X <- 1:7
>> Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
>> 213484643920, 580311678200)
>> plot(Y~X)
>> ```
>> The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
>> axis does not start at 1e9?
>> 
>> 
>> 
>> --
>> Best regards,
>> Luigi
>> 
>> __
>> 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] plot shows exponential values incompatible with data

2020-07-10 Thread Luigi Marongiu
Thank you!
I reckon the main problem is the large data range, anyway. I should
stick with logarithmic scales...
Best regards
Luigi

On Fri, Jul 10, 2020 at 6:14 AM Jim Lemon  wrote:
>
> Hi Luigi,
> This is a result of the "pretty" function that calculates hopefully
> good looking axis ticks automatically. You can always specify
> ylim=c(1.0E09,max(Y)) if you want.
>
> Jim
>
> On Thu, Jul 9, 2020 at 10:59 PM Luigi Marongiu  
> wrote:
> >
> > Hello,
> > I have these vectors:
> > ```
> > X <- 1:7
> > Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
> > 213484643920, 580311678200)
> > plot(Y~X)
> > ```
> > The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
> > axis does not start at 1e9?
> >
> >
> >
> > --
> > Best regards,
> > Luigi
> >
> > __
> > 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.



-- 
Best regards,
Luigi

__
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 shows exponential values incompatible with data

2020-07-09 Thread Jim Lemon
Hi Luigi,
This is a result of the "pretty" function that calculates hopefully
good looking axis ticks automatically. You can always specify
ylim=c(1.0E09,max(Y)) if you want.

Jim

On Thu, Jul 9, 2020 at 10:59 PM Luigi Marongiu  wrote:
>
> Hello,
> I have these vectors:
> ```
> X <- 1:7
> Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
> 213484643920, 580311678200)
> plot(Y~X)
> ```
> The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
> axis does not start at 1e9?
>
>
>
> --
> Best regards,
> Luigi
>
> __
> 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 shows exponential values incompatible with data

2020-07-09 Thread Fox, John
Dear Bernard,

> On Jul 9, 2020, at 10:25 AM, Bernard Comcast  
> wrote:
> 
> Use the xlim option in the plot function?

I think you mean ylim, but as you'll find out when you try it, you still 
(reasonably) get an evenly spaced tick mark at 0:

plot(Y ~ X, ylim=c(1e9, 6e11))

The "right" thing to do with exponential values is to plot on a log scale or 
(as Rui reasonably suggested) use a logged axis.

Best,
 John

> 
> Bernard
> Sent from my iPhone so please excuse the spelling!"
> 
>> On Jul 9, 2020, at 10:06 AM, Luigi Marongiu  wrote:
>> 
>> Thank you,
>> but why it does not work in linear? With the log scale, I know it
>> works but I am not looking for it; is there a way to force a linear
>> scale?
>> Regards
>> Luigi
>> 
>>> On Thu, Jul 9, 2020 at 3:44 PM Fox, John  wrote:
>>> 
>>> Dear Luigi,
>>> 
> On Jul 9, 2020, at 8:59 AM, Luigi Marongiu  
> wrote:
 
 Hello,
 I have these vectors:
 ```
 X <- 1:7
 Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
 213484643920, 580311678200)
 plot(Y~X)
 ```
 The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
 axis does not start at 1e9?
>>> 
>>> Because you're plotting on a linear, not log, scale, and 0*10^11 = 0.
>>> 
 round(Y/1e11)
>>> [1] 0 0 0 0 1 2 6
>>> 
>>> Then try plot(log(Y) ~ X).
>>> 
>>> I hope this helps,
>>> John
>>> 
>>> -
>>> John Fox, Professor Emeritus
>>> McMaster University
>>> Hamilton, Ontario, Canada
>>> Web: http::/socserv.mcmaster.ca/jfox
 
 
 
 --
 Best regards,
 Luigi
 
 __
 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.
>>> 
>> 
>> 
>> -- 
>> Best regards,
>> Luigi
>> 
>> __
>> 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] plot shows exponential values incompatible with data

2020-07-09 Thread Rui Barradas

Hello,

Like this?

plot(Y~X, log="y")



Hope this helps,

Rui Barradas

Às 14:59 de 09/07/20, Luigi Marongiu escreveu:

Thank you,
but why it does not work in linear? With the log scale, I know it
works but I am not looking for it; is there a way to force a linear
scale?
Regards
Luigi

On Thu, Jul 9, 2020 at 3:44 PM Fox, John  wrote:


Dear Luigi,


On Jul 9, 2020, at 8:59 AM, Luigi Marongiu  wrote:

Hello,
I have these vectors:
```
X <- 1:7
Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
213484643920, 580311678200)
plot(Y~X)
```
The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
axis does not start at 1e9?


Because you're plotting on a linear, not log, scale, and 0*10^11 = 0.


round(Y/1e11)

[1] 0 0 0 0 1 2 6

Then try plot(log(Y) ~ X).

I hope this helps,
  John

   -
   John Fox, Professor Emeritus
   McMaster University
   Hamilton, Ontario, Canada
   Web: http::/socserv.mcmaster.ca/jfox




--
Best regards,
Luigi

__
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 shows exponential values incompatible with data

2020-07-09 Thread Bernard Comcast
Use the xlim option in the plot function?

Bernard
Sent from my iPhone so please excuse the spelling!"

> On Jul 9, 2020, at 10:06 AM, Luigi Marongiu  wrote:
> 
> Thank you,
> but why it does not work in linear? With the log scale, I know it
> works but I am not looking for it; is there a way to force a linear
> scale?
> Regards
> Luigi
> 
>> On Thu, Jul 9, 2020 at 3:44 PM Fox, John  wrote:
>> 
>> Dear Luigi,
>> 
 On Jul 9, 2020, at 8:59 AM, Luigi Marongiu  
 wrote:
>>> 
>>> Hello,
>>> I have these vectors:
>>> ```
>>> X <- 1:7
>>> Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
>>> 213484643920, 580311678200)
>>> plot(Y~X)
>>> ```
>>> The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
>>> axis does not start at 1e9?
>> 
>> Because you're plotting on a linear, not log, scale, and 0*10^11 = 0.
>> 
>>> round(Y/1e11)
>> [1] 0 0 0 0 1 2 6
>> 
>> Then try plot(log(Y) ~ X).
>> 
>> I hope this helps,
>> John
>> 
>>  -
>>  John Fox, Professor Emeritus
>>  McMaster University
>>  Hamilton, Ontario, Canada
>>  Web: http::/socserv.mcmaster.ca/jfox
>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> Luigi
>>> 
>>> __
>>> 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.
>> 
> 
> 
> -- 
> Best regards,
> Luigi
> 
> __
> 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 shows exponential values incompatible with data

2020-07-09 Thread Bert Gunter
Please consult ?axis and follow its links (e.g. "axTicks" and "pretty") for
the details of the algorithm used to construct axis annotation.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jul 9, 2020 at 5:59 AM Luigi Marongiu 
wrote:

> Hello,
> I have these vectors:
> ```
> X <- 1:7
> Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
> 213484643920, 580311678200)
> plot(Y~X)
> ```
> The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
> axis does not start at 1e9?
>
>
>
> --
> Best regards,
> Luigi
>
> __
> 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] plot shows exponential values incompatible with data

2020-07-09 Thread Fox, John
Dear Luigi,

> On Jul 9, 2020, at 9:59 AM, Luigi Marongiu  wrote:
> 
> Thank you,
> but why it does not work in linear? With the log scale, I know it
> works but I am not looking for it; is there a way to force a linear
> scale?

The scale *is* linear and the choice of tick marks, which are evenly spaced, is 
reasonable, given that 10^9 is 2 orders of magnitude smaller than 10^11. That 
is, on a linear scale with this range, 10^9 isn't much larger than 0.

If you really want a tick at 10^9, then you can just put one there:

plot(Y~X, axes=FALSE, frame=TRUE)
axis(1)
axis(2, at=c(1e9, (1:6)*1e11))

But now the ticks aren't evenly spaced (though they appear to be because, as I 
mentioned, 10^9 is "close" to 0).

Best,
 John

> Regards
> Luigi
> 
> On Thu, Jul 9, 2020 at 3:44 PM Fox, John  wrote:
>> 
>> Dear Luigi,
>> 
>>> On Jul 9, 2020, at 8:59 AM, Luigi Marongiu  wrote:
>>> 
>>> Hello,
>>> I have these vectors:
>>> ```
>>> X <- 1:7
>>> Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
>>> 213484643920, 580311678200)
>>> plot(Y~X)
>>> ```
>>> The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
>>> axis does not start at 1e9?
>> 
>> Because you're plotting on a linear, not log, scale, and 0*10^11 = 0.
>> 
>>> round(Y/1e11)
>> [1] 0 0 0 0 1 2 6
>> 
>> Then try plot(log(Y) ~ X).
>> 
>> I hope this helps,
>> John
>> 
>>  -
>>  John Fox, Professor Emeritus
>>  McMaster University
>>  Hamilton, Ontario, Canada
>>  Web: http::/socserv.mcmaster.ca/jfox
>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> Luigi
>>> 
>>> __
>>> 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.
>> 
> 
> 
> -- 
> Best regards,
> Luigi
> 
> __
> 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 shows exponential values incompatible with data

2020-07-09 Thread Luigi Marongiu
Thank you,
but why it does not work in linear? With the log scale, I know it
works but I am not looking for it; is there a way to force a linear
scale?
Regards
Luigi

On Thu, Jul 9, 2020 at 3:44 PM Fox, John  wrote:
>
> Dear Luigi,
>
> > On Jul 9, 2020, at 8:59 AM, Luigi Marongiu  wrote:
> >
> > Hello,
> > I have these vectors:
> > ```
> > X <- 1:7
> > Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
> > 213484643920, 580311678200)
> > plot(Y~X)
> > ```
> > The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
> > axis does not start at 1e9?
>
> Because you're plotting on a linear, not log, scale, and 0*10^11 = 0.
>
> > round(Y/1e11)
> [1] 0 0 0 0 1 2 6
>
> Then try plot(log(Y) ~ X).
>
> I hope this helps,
>  John
>
>   -
>   John Fox, Professor Emeritus
>   McMaster University
>   Hamilton, Ontario, Canada
>   Web: http::/socserv.mcmaster.ca/jfox
> >
> >
> >
> > --
> > Best regards,
> > Luigi
> >
> > __
> > 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.
>


-- 
Best regards,
Luigi

__
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 shows exponential values incompatible with data

2020-07-09 Thread Fox, John
Dear Luigi,

> On Jul 9, 2020, at 8:59 AM, Luigi Marongiu  wrote:
> 
> Hello,
> I have these vectors:
> ```
> X <- 1:7
> Y <- c(1438443863, 3910100650, 10628760108, 28891979048, 78536576706,
> 213484643920, 580311678200)
> plot(Y~X)
> ```
> The y-axis starts at 0e0, but the first value is 1.4 billion. Why the
> axis does not start at 1e9?

Because you're plotting on a linear, not log, scale, and 0*10^11 = 0. 

> round(Y/1e11)
[1] 0 0 0 0 1 2 6

Then try plot(log(Y) ~ X).

I hope this helps,
 John

  -
  John Fox, Professor Emeritus
  McMaster University
  Hamilton, Ontario, Canada
  Web: http::/socserv.mcmaster.ca/jfox
> 
> 
> 
> -- 
> Best regards,
> Luigi
> 
> __
> 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 two values on same axes

2019-09-27 Thread Rich Shepard

On Fri, 27 Sep 2019, Rolf Turner wrote:


You may better off using base R graphics, unless there are considerations
which demand the use of lattice. Something like this, maybe:

plot(maxtemp ~ sampdate, data=watertemp, type="h", col="red",
)
points(maxtemp ~ sampdate, data=watertemp, type="h",col="blue")


Rolf,

Thanks very much.

Regards,

Rich

__
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 two values on same axes

2019-09-27 Thread Rich Shepard

On Fri, 27 Sep 2019, David Winsemius wrote:


Instead of trying to mix lattice and base functions, you might try using
the formula:

maxtemp+mintemp ~ sampdate

And then: col= c(“red”, “blue”)


David,

I certainly will. I've not needed R for projects for many months and when I
looked through previous scripts and the lattice book I failed to find what I
needed. So what I tried was a solution to a different but similar issue on
stackexchange.

Many thanks,

Rich

__
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 two values on same axes

2019-09-26 Thread Rolf Turner



On 27/09/19 10:27 AM, Rich Shepard wrote:


I want to plot maximum and minimum water temperatures on the same axes and
thought I had the correct syntax:

watertemp <- read.table("../../data/hydro/water-temp.dat", header = 
TRUE, sep =",")

watertemp$sampdate <- as.Date(as.character(watertemp$sampdate))
watertempsum <- summary(watertemp)
print(watertempsum)
maxwatemp <- xyplot(maxtemp ~ sampdate, data=watertemp, col="red", 
type="h", main="USGS Foss Gauge Water Temperatures, 1974-1981", 
ylab="Temperature (C)", xlab="Date", scales=list(tck=c(1,0)))
minwatemp <- xyplot(mintemp ~ sampdate, data=watertemp, col="blue", 
type="h")

plot(maxwatemp)
par(new=TRUE)
plot(minwatemp)

However, R plots only minwatemp and displays this:
Warning message:
In par(new = TRUE) : calling par(new=TRUE) with no plot

Despite my searching for the reason I don't see what syntax error I made.
The two questions I ask of you:

1. Where have I gone wrong in this script?

2. With 2,492 daily observations in the source file (including 242 NAs for
maxtemp and 243 NAs for mintemp), what would be a more appropriate plot to
show both sets of data?


You are using xyplot() from the lattice package (which you did not 
mention).  Your par(new=TRUE) syntax would probably work with base R 
graphics (although it would be suboptimal; one would normally use 
points() to add a second graph on the same figure).  I would hazard that 
it won't work at all with lattice graphics.


Moreover you seem to be trying to mix lattice graphics and base R 
graphics in a higgledy-piggledy fashion:  first you call xyplot() and 
then you call plot().


To do what you want with lattice graphics I think you need to learn 
about and apply *panels* --- in particular panel.points().  Using panels 
appropriately is a bit tricky, I find, and requires some study.


You may better off using base R graphics, unless there are 
considerations which demand the use of lattice.  Something like this, maybe:


plot(maxtemp ~ sampdate, data=watertemp, type="h", col="red",
 )
points(maxtemp ~ sampdate, data=watertemp, type="h",col="blue")

(Not tested since your example is not reproducible.)

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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 two values on same axes

2019-09-26 Thread David Winsemius
Instead of trying to mix lattice and base functions, you might try using the 
formula:

maxtemp+mintemp ~ sampdate

And then: col= c(“red”, “blue”)

Sent from my iPhone, so make sure those quotes are ordinary double quotes. 

— 
David


> On Sep 27, 2019, at 6:27 AM, Rich Shepard  wrote:
> 
> I want to plot maximum and minimum water temperatures on the same axes and
> thought I had the correct syntax:
> 
> watertemp <- read.table("../../data/hydro/water-temp.dat", header = TRUE, sep 
> =",")
> watertemp$sampdate <- as.Date(as.character(watertemp$sampdate))
> watertempsum <- summary(watertemp)
> print(watertempsum)
> maxwatemp <- xyplot(maxtemp ~ sampdate, data=watertemp, col="red", type="h", 
> main="USGS Foss Gauge Water Temperatures, 1974-1981", ylab="Temperature (C)", 
> xlab="Date", scales=list(tck=c(1,0)))
> minwatemp <- xyplot(mintemp ~ sampdate, data=watertemp, col="blue", type="h")
> plot(maxwatemp)
> par(new=TRUE)
> plot(minwatemp)
> 
> However, R plots only minwatemp and displays this:
> Warning message:
> In par(new = TRUE) : calling par(new=TRUE) with no plot
> 
> Despite my searching for the reason I don't see what syntax error I made.
> The two questions I ask of you:
> 
> 1. Where have I gone wrong in this script?
> 
> 2. With 2,492 daily observations in the source file (including 242 NAs for
> maxtemp and 243 NAs for mintemp), what would be a more appropriate plot to
> show both sets of data?
> 
> Thanks in advance,
> 
> Rich
> 
> __
> 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 historical data

2019-06-19 Thread Abby Spurdle
I'm not sure I understand exactly what you mean.

> I want to EXTRACT FOR ONE HAND A TABLE WITH MEAN BY CENTER, STD DESV.

Do you want a table giving the mean and sd of Cost, grouped by Center?

> I want a plot or smooth plot replicating a gauss line distribution by
> center.

Do you want one plot for each Center, showing the normal distribution of
Cost?
Or you want one plot for each Center, showing a kernel density estimate of
Cost?
Or you want one plot for each Center, showing the ECDF of Cost?
All are possible.

> and to save each plot in a jpeg file

I recommend PDF format.
(Vector graphics tend to have higher quality than raster graphics).
Are you sure you want JPEG format?

> How should I compare distribution empirical line of center M with C?

Do you want to compare the ECDF of Cost, for Center M and Center C?
If so, you can produce one plot, with both distributions.
Or you can plot each next to each other?
The first option is probably better, but you need to be careful with the
horizontal axis.

However, I'm wondering if you want a kernel density estimate?


Abs

[[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 (cox)

2019-04-15 Thread Medic
Dear Sarah,
everything worked out! Thank You!!!
--
Sarah Goslee :
> Well, you don't provide a reproducible example, so there's only so
> much we can do. The help for par is a lot, but I told you which option
> to use. Did you try reading the examples for ?axis at all?
> plot (cox, col=1:2, xscale=1, xlab="OS",  ylab="Probability", xaxt="n")
> axis(1, at=seq(0, 48, by=12))
> Or whatever axis values you actually want.

> > Sarah Goslee :
> > > You can presumably use xaxt="n" in your plot() statement (see ?par for
> > > details), and then use axis() to make anything you'd like (see ?axis
> > > for details).
> > --
> > >> Medic  wrote:
> > >> In this code:
> > >> plot (cox, col=1:2, xscale=1, xlab="OS",  ylab="Probability")
> > >> the X scale is divided (by default) as:
> > >>  0 ... 50 ... 100 ... 150 ... 200
> > >> And I would like so:
> > >> 0 ... 12 ... 24 ... 36 ... 48.
> > >> I looked ?plot(cox), but did not understand what argument is
> > >> responsible for this.

__
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 (cox)

2019-04-15 Thread Sarah Goslee
Well, you don't provide a reproducible example, so there's only so
much we can do. The help for par is a lot, but I told you which option
to use.
Did you try reading the examples for ?axis at all?


plot (cox, col=1:2, xscale=1, xlab="OS",  ylab="Probability", xaxt="n")
axis(1, at=seq(0, 48, by=12))

Or whatever axis values you actually want.

Sarah

On Mon, Apr 15, 2019 at 3:02 PM Medic  wrote:
>
> Thanks, but too hard for me
>
> Sarah Goslee :
> > You can presumably use xaxt="n" in your plot() statement (see ?par for
> > details), and then use axis() to make anything you'd like (see ?axis
> > for details).
> --
> >> Medic  wrote:
> >> In this code:
> >> plot (cox, col=1:2, xscale=1, xlab="OS",  ylab="Probability")
> >> the X scale is divided (by default) as:
> >>  0 ... 50 ... 100 ... 150 ... 200
> >> And I would like so:
> >> 0 ... 12 ... 24 ... 36 ... 48.
> >> I looked ?plot(cox), but did not understand what argument is
> >> responsible for this.



-- 
Sarah Goslee (she/her)
http://www.numberwright.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] plot (cox)

2019-04-15 Thread Medic
Thanks, but too hard for me

Sarah Goslee :
> You can presumably use xaxt="n" in your plot() statement (see ?par for
> details), and then use axis() to make anything you'd like (see ?axis
> for details).
--
>> Medic  wrote:
>> In this code:
>> plot (cox, col=1:2, xscale=1, xlab="OS",  ylab="Probability")
>> the X scale is divided (by default) as:
>>  0 ... 50 ... 100 ... 150 ... 200
>> And I would like so:
>> 0 ... 12 ... 24 ... 36 ... 48.
>> I looked ?plot(cox), but did not understand what argument is
>> responsible for this.

__
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 coordinates on world map with Robinson CRS - ggplot2

2019-02-18 Thread Jeff Newmiller
This is the wrong place for this question.

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

On February 18, 2019 12:57:38 AM PST, Miluji Sb  wrote:
>Dear all,
>
>I am trying to plot coordinates on a world map with Robinson CRS. While
>the
>world map is generated without any issues, when I try to plot the
>points -
>I only get a single point.
>
>The code I am using and the coordinates data is below. What am I doing
>wrong? Any help/suggestions will be highly appreciated.
>
>library(data.table)
>library(foreign)
>library(readstata13)
>library(rgdal)
>library(maptools)
>library(ggplot2)
>library(dplyr)
>
>load(url("
>https://github.com/valentinitnelav/RandomScripts/blob/master/NaturalEarth.RData?raw=true
>"))
>
>PROJ <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84
>+units=m +no_defs"
>
>NE_countries_rob  <- spTransform(NE_countries, CRSobj = PROJ)
>NE_graticules_rob <- spTransform(NE_graticules, CRSobj = PROJ)
>NE_box_rob<- spTransform(NE_box, CRSobj = PROJ)
>
># project long-lat coordinates for graticule label data frames
># (two extra columns with projected XY are created)
>prj.coord <- project(cbind(lbl.Y$lon, lbl.Y$lat), proj=PROJ)
>lbl.Y.prj <- cbind(prj.coord, lbl.Y)
>names(lbl.Y.prj)[1:2] <- c("X.prj","Y.prj")
>
>prj.coord <- project(cbind(lbl.X$lon, lbl.X$lat), proj=PROJ)
>lbl.X.prj <- cbind(prj.coord, lbl.X)
>names(lbl.X.prj)[1:2] <- c("X.prj","Y.prj")
>
>m <- ggplot() +
> # add Natural Earth countries projected to Robinson, give black border
>and fill with gray
>  geom_polygon(data=NE_countries_rob, aes(long,lat, group=group),
>colour="black", fill="gray80", size = 0.25) +
>  # Note: "Regions defined for each Polygons" warning has to do with
>fortify transformation. Might get deprecated in future!
>  # alternatively, use use map_data(NE_countries) to transform to data
>frame and then use project() to change to desired projection.
>  # add Natural Earth box projected to Robinson
>  geom_polygon(data=NE_box_rob, aes(x=long, y=lat), colour="black",
>fill="transparent", size = 0.25) +
>  # add graticules projected to Robinson
>  geom_path(data=NE_graticules_rob, aes(long, lat, group=group),
>linetype="dotted", color="grey50", size = 0.25) +
>  # add graticule labels - latitude and longitude
>  geom_text(data = lbl.Y.prj, aes(x = X.prj, y = Y.prj, label = lbl),
>color="grey50", size=2) +
>  geom_text(data = lbl.X.prj, aes(x = X.prj, y = Y.prj, label = lbl),
>color="grey50", size=2) +
>  # the default, ratio = 1 in coord_fixed ensures that one unit on the
>x-axis is the same length as one unit on the y-axis
>  coord_fixed(ratio = 1) +
>  geom_point(data=df,
> aes(x=lon, y=lat), colour="Deep Pink",
> fill="Pink",pch=21, size=2, alpha=I(0.7))
>  # remove the background and default gridlines
>  theme_void()
>
>## coordinates dataframe
>dput(df)
>structure(list(lon = c(2.67569724621467, 17.5766416259819,
>28.4126232192772,
>23.8147674538232, 29.8917589327105), lat = c(28.1503115976162,
>-12.3388787380201, 9.78891068739477, -22.1873831176644,
>-3.36546931479253
>)), class = "data.frame", row.names = c(NA, -5L))
>
>Sincerely,
>
>Milu
>
>   [[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.


Re: [R] [FORGED] Re: R plot split screen in uneven panels

2018-12-13 Thread Rolf Turner



On 12/14/18 1:44 AM, Luigi Marongiu wrote:


Thank you, that worked good. I tried to read the help for
layout/split.screen but I found it confusing.




Me too.  I conjecture that *everybody* finds it confusing, except maybe 
Paul M., and I'm not so sure about him! :-)


However it *is possible* to fight your way through the help. 
Experimenting is useful!  And when you succeed in fighting your way 
through, it works *well*.  (Not "good"!!!)


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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 a matrix

2018-11-01 Thread David L Carlson
It would be much better if you had pasted the original .csv file into your 
message or read the file in R and used dput() to send us the result. It looks 
like you have a lower triangular matrix and I had to do a little editing to get 
it to work. I am showing the steps, but commenting them out since you will only 
need the command following dput(mcdf2). The first row should end with 41848 and 
every row show begin with #. 

# dta <- "rows 41540 41442 41599 41709 41823 41806 41837 41898 41848
#  41540 NA
#  41442 0.001
#  41599 0.002 0.001
#  41709 0.004 0.003 0.003
#  41823 0.002 0.001 0.002 0.001
#  41806 0.004 0.004 0.005 0.006 0.005
#  41837 0.004 0.004 0.005 0.006 0.005 0.001
#  41898 0.004 0.004 0.005 0.006 0.005 0.001 0.001
#  41848 0.005 0.004 0.005 0.007 0.005 0.001 0.001 0.001 NA"
# mcdf<-read.table(text=dta, header=TRUE, fill=TRUE)
# mcdf
# rownames(mcdf) <- mcdf$rows
# mcdf <- mcdf[, -1]
# mcdf2 <- as.dist(mcdf)
# mcdf2
# dput(mcdf2)

mcdf2 <- structure(c(0.001, 0.002, 0.004, 0.002, 0.004, 0.004, 0.004, 
0.005, 0.001, 0.003, 0.001, 0.004, 0.004, 0.004, 0.004, 0.003, 
0.002, 0.005, 0.005, 0.005, 0.005, 0.001, 0.006, 0.006, 0.006, 
0.007, 0.005, 0.005, 0.005, 0.005, 0.001, 0.001, 0.001, 0.001, 
0.001, 0.001), Labels = c("41540", "41442", "41599", "41709", 
"41823", "41806", "41837", "41898", "41848"), Size = 9L,
call = as.dist.default(m = mcdf), class = "dist", Diag = FALSE,
Upper = FALSE)

Now mcdf2 is a lower triangular distance matrix:

str(mcdf2)
#  'dist' num [1:36] 0.001 0.002 0.004 0.002 0.004 0.004 0.004 0.005 0.001 
0.003 ...
#  - attr(*, "Labels")= chr [1:9] "41540" "41442" "41599" "41709" ...
#  - attr(*, "Size")= int 9
#  - attr(*, "call")= language as.dist.default(m = mcdf)
#  - attr(*, "Diag")= logi FALSE
# - attr(*, "Upper")= logi FALSE

The days are stored as an attribute called "Labels" so we need to extract them 
and compute the differences between them:

days <- as.numeric(attributes(mcdf2)$Labels)
daydiff <- dist(days, method="manhattan")
daydiff
# 1   2   3   4   5   6   7   8
# 2  98
# 3  59 157
# 4 169 267 110
# 5 283 381 224 114
# 6 266 364 207  97  17
# 7 297 395 238 128  14  31
# 8 358 456 299 189  75  92  61
# 9 308 406 249 139  25  42  11  50

Now we can plot. I've attached a copy:

plot(daydiff, mcdf2)

You need to read the following manual pages to understand what we are doing:

?read.table
?rownames
?as.dist
?dput
?as.numeric
?attributes
?dist
?plot
?Extract (to understand what the "$" is all about.


David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77843-4352

Original Message-
From: R-help  On Behalf Of Jim Lemon
Sent: Thursday, November 1, 2018 1:56 AM
To: myriam.croz...@gmail.com
Cc: r-help mailing list 
Subject: Re: [R] Plot a matrix

Hi Myriam,
This may not be the ideal way to do this, but I think it works:

mcdf<-read.table(text="41540 41540 41442 41599 41709 41823 41806 41837
41898 41848
41442 0.001
41599 0.002 0.001
41709 0.004 0.003 0.003
41823 0.002 0.001 0.002 0.001
41806 0.004 0.004 0.005 0.006 0.005
41837 0.004 0.004 0.005 0.006 0.005 0.001
41898 0.004 0.004 0.005 0.006 0.005 0.001 0.001
41848 0.005 0.004 0.005 0.007 0.005 0.001 0.001 0.001",
fill=TRUE)
nrows<-nrow(mcdf)
ncols<-ncol(mcdf)
mcdf2<-mcdf
for(row in 2:nrows) {
 for(col in 2:ncols) {
  if(!is.na(mcdf2[row,col])) mcdf2[row,col]<-mcdf[row,1]-mcdf[1,col]
 }
}
plot(0,xlim=range(as.numeric(unlist(mcdf2[2:nrows,2:ncols])),na.rm=TRUE),
 ylim=range(as.numeric(unlist(mcdf[2:nrows,2:ncols])),na.rm=TRUE),
 xlab="Difference in days",ylab="Distance",type="n")
for(row in 2:nrows) {
 for(col in 2:ncols) {
  if(!is.na(mcdf2[row,col])) points(mcdf2[row,col],mcdf[row,col])
 }
}

Jim
On Thu, Nov 1, 2018 at 5:21 PM Myriam Croze  wrote:
>
> Hello!
>
> I need your help to plot my data. I have a file .csv which looks like that:
>
> 41540 41540 41442 41599 41709 41823 41806 41837 41898 41848
> 41442 0.001
> 41599 0.002 0.001
> 41709 0.004 0.003 0.003
> 41823 0.002 0.001 0.002 0.001
> 41806 0.004 0.004 0.005 0.006 0.005
> 41837 0.004 0.004 0.005 0.006 0.005 0.001
> 41898 0.004 0.004 0.005 0.006 0.005 0.001 0.001
> 41848 0.005 0.004 0.005 0.007 0.005 0.001 0.001 0.001
>
> It is a matrix of distance with in the 1st column and row the days of
> sampling and then the distance values.
> I would like to do a scatterplot of the data with for the y axis the
> distance values and for the x axis the difference between the days of
> sampling (e.g. x = |41442-41540| an

Re: [R] Plot a path

2018-11-01 Thread Jan van der Laan
Below a similar example, using sf and leaflet; plotting the trajectory 
on a background map.



library(leaflet)
library(sf)
library(dplyr)

# Generate example data
gen_data <- function(id, n) {
  data.frame(
id = id,
date = 1:n,
lat = runif(10, min = -90, max = 90),
lon = runif(10, min = -180, max = 180)
  )
}

dta <- lapply(1:2, gen_data, n = 10) %>% bind_rows()

# Transform all records of one object/person to a st_linestring, then
# combine into one sf column
lines <- dta %>%
  arrange(id, date) %>%
  split(dta$id) %>%
  lapply(function(d) st_linestring(cbind(d$lon, d$lat))) %>%
  unname() %>%   # Without the unname it doesn't work for some reason
  st_sfc()

# Plot using leaflet
leaflet() %>%
  addTiles() %>%
  addPolylines(data = lines)


HTH - Jan


On 01-11-18 11:27, Rui Barradas wrote:

Hello,

The following uses ggplot2.

First, make up a dataset, since you have not posted one.



lat0 <- 38.736946
lon0 <- -9.142685
n <- 10

set.seed(1)
Date <- seq(Sys.Date() - n + 1, Sys.Date(), by = "days")
Lat <- lat0 + cumsum(c(0, runif(n - 1)))
Lon <- lon0 + cumsum(c(0, runif(n - 1)))
Placename <- rep(c("A", "B"), n/2)

path <- data.frame(Date, Placename, Lat, Lon)
path <- path[order(path$Date), ]


Now, two graphs, one with just one line of all the lon/lat and the other 
with a line for each Placename.


library(ggplot2)

ggplot(path, aes(x = Lon, y = Lat)) +
   geom_point() +
   geom_line()


ggplot(path, aes(x = Lon, y = Lat, colour = Placename)) +
   geom_point(aes(fill = Placename)) +
   geom_line()


Hope this helps,

Rui Barradas

Às 21:27 de 31/10/2018, Ferri Leberl escreveu:


Dear All,
I have a dataframe with four cols: Date, Placename, geogr. latitude, 
geogr. longitude.
How can I plot the path as a line, ordered by the date, with the 
longitude as the x-axis and the latitude as the y-axis?

Thank you in advance!
Yours, Ferri

__
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] Plot a path

2018-11-01 Thread Rui Barradas

Hello,

The following uses ggplot2.

First, make up a dataset, since you have not posted one.



lat0 <- 38.736946
lon0 <- -9.142685
n <- 10

set.seed(1)
Date <- seq(Sys.Date() - n + 1, Sys.Date(), by = "days")
Lat <- lat0 + cumsum(c(0, runif(n - 1)))
Lon <- lon0 + cumsum(c(0, runif(n - 1)))
Placename <- rep(c("A", "B"), n/2)

path <- data.frame(Date, Placename, Lat, Lon)
path <- path[order(path$Date), ]


Now, two graphs, one with just one line of all the lon/lat and the other 
with a line for each Placename.


library(ggplot2)

ggplot(path, aes(x = Lon, y = Lat)) +
  geom_point() +
  geom_line()


ggplot(path, aes(x = Lon, y = Lat, colour = Placename)) +
  geom_point(aes(fill = Placename)) +
  geom_line()


Hope this helps,

Rui Barradas

Às 21:27 de 31/10/2018, Ferri Leberl escreveu:


Dear All,
I have a dataframe with four cols: Date, Placename, geogr. latitude, geogr. 
longitude.
How can I plot the path as a line, ordered by the date, with the longitude as 
the x-axis and the latitude as the y-axis?
Thank you in advance!
Yours, Ferri

__
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 a matrix

2018-11-01 Thread Jim Lemon
Hi Myriam,
This may not be the ideal way to do this, but I think it works:

mcdf<-read.table(text="41540 41540 41442 41599 41709 41823 41806 41837
41898 41848
41442 0.001
41599 0.002 0.001
41709 0.004 0.003 0.003
41823 0.002 0.001 0.002 0.001
41806 0.004 0.004 0.005 0.006 0.005
41837 0.004 0.004 0.005 0.006 0.005 0.001
41898 0.004 0.004 0.005 0.006 0.005 0.001 0.001
41848 0.005 0.004 0.005 0.007 0.005 0.001 0.001 0.001",
fill=TRUE)
nrows<-nrow(mcdf)
ncols<-ncol(mcdf)
mcdf2<-mcdf
for(row in 2:nrows) {
 for(col in 2:ncols) {
  if(!is.na(mcdf2[row,col])) mcdf2[row,col]<-mcdf[row,1]-mcdf[1,col]
 }
}
plot(0,xlim=range(as.numeric(unlist(mcdf2[2:nrows,2:ncols])),na.rm=TRUE),
 ylim=range(as.numeric(unlist(mcdf[2:nrows,2:ncols])),na.rm=TRUE),
 xlab="Difference in days",ylab="Distance",type="n")
for(row in 2:nrows) {
 for(col in 2:ncols) {
  if(!is.na(mcdf2[row,col])) points(mcdf2[row,col],mcdf[row,col])
 }
}

Jim
On Thu, Nov 1, 2018 at 5:21 PM Myriam Croze  wrote:
>
> Hello!
>
> I need your help to plot my data. I have a file .csv which looks like that:
>
> 41540 41540 41442 41599 41709 41823 41806 41837 41898 41848
> 41442 0.001
> 41599 0.002 0.001
> 41709 0.004 0.003 0.003
> 41823 0.002 0.001 0.002 0.001
> 41806 0.004 0.004 0.005 0.006 0.005
> 41837 0.004 0.004 0.005 0.006 0.005 0.001
> 41898 0.004 0.004 0.005 0.006 0.005 0.001 0.001
> 41848 0.005 0.004 0.005 0.007 0.005 0.001 0.001 0.001
>
> It is a matrix of distance with in the 1st column and row the days of
> sampling and then the distance values.
> I would like to do a scatterplot of the data with for the y axis the
> distance values and for the x axis the difference between the days of
> sampling (e.g. x = |41442-41540| and y = 0.001).
> Do you know how I could do that with r?
> Thanks in advance for your help.
>
> Best regards,
> Myriam
>
> --
> Myriam Croze
> Post-doctorante
> Division of EcoScience,
> Ewha Womans University
> Seoul, South Korea
>
> Email: myriam.croz...@gmail.com
>
> [[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] Plot a path

2018-10-31 Thread MacQueen, Don via R-help
Probably
   sort the data frame by date
Then
  plot( mydf$geogr.longitude, mydf$geogr.latitude, type='l')

Search the web for some tutorials

See the help pages for
   plot
   plot.default

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 10/31/18, 2:27 PM, "R-help on behalf of Ferri Leberl" 
 wrote:


Dear All,
I have a dataframe with four cols: Date, Placename, geogr. latitude, geogr. 
longitude.
How can I plot the path as a line, ordered by the date, with the longitude 
as the x-axis and the latitude as the y-axis?
Thank you in advance!
Yours, Ferri

__
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 in real unit (1:1)

2018-10-08 Thread Christian Brandstätter
Dar Jim, 
late, but it works now perfectly. I made a little function for
autoscaling elevation data. 
https://stackoverflow.com/questions/50606797/plot-in-real-units-mm/52696705#52696705The
 (paper-)printer typically also autoscales, which needs to be
deactivated.  
Example for a plot with scale  in y and x direction: 
in2mm<-25.4

mx = 1000 # Scale X # input unit m
my = 2000 # Scale Y # input unit m

pdf("test_size.pdf",width=210/in2mm,height=297/in2mm,paper="special")
par(mar= c(5.1,4.1,4.1,1.1))
pin <- par("pin") # returns plotheight and -width

yvalue <- sort(sample(1:1000,200))
xvalue <- sort(sample(1:500,200))

xplus <- diff(range(c(0,pin[1]*in2mm)))*(mx/1000)/2
yplus <- diff(range(c(0,pin[2]*in2mm)))*(my/1000)/2

plot(xvalue,yvalue,#asp=mx/my,
 type="n", xaxs="i", yaxs="i",
 xlim=c(mean(xvalue)-xplus,mean(xvalue)+xplus),
 ylim=c(mean(yvalue)-yplus,mean(yvalue)+yplus),
 ylab="vertical [m]",xlab="horizontal [m]")

lines(xvalue,yvalue,type="l",col="black")

legend(x="topleft",horiz=TRUE,
   legend=c(paste0("Mx: 1:",mx),paste0("My: 1:",my),
paste0("Vertical Exaggeration:
1:",mx/my)),x.intersp=0,bty="n")

dev.off()
On Thu, 2018-06-07 at 14:13 +1000, Jim Lemon wrote:
> Hi Christian,Well, it almost worked. I suspect that the postscript
> device adds somepadding to account for the printable area, so with a
> bit ofexperimentation, The following example seems to do what you
> want. WhenI printed the resulting file from the GIMP, the box and
> diamond werethe correct dimensions.
> postscript("test.ps",paper="a4",horizontal=FALSE)par(mai=c(1.713,0,1.
> 713,0),xaxs="i",yaxs="i")plot(0,type="n",xlim=c(0,190),ylim=c(0,190),
> xlab="",axes=FALSE)segments(c(0,95),c(95,0),c(190,95),c(95,190))segme
> nts(c(45,95,145,95),c(95,145,95,45),
> c(95,145,95,45),c(145,95,45,95))box()dev.off()
> Jim
> On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon 
> wrote:Hi Christian,When I have to do something like this, I usually
> write it inPostscript using this:
> /def mm 2.8346 mul
> that converts a dimension in mm to points (1/72 inch). However,
> thiswon't work in R. It may be possible to set up the device like
> this:
> postscript("myfile.ps",paper="a4")par(mar=c(0,0,0,0))# generate a
> blank plotplot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE)#
> display lines, etc. in mm with 0,0 at the bottom leftdev.off()
> The resulting file should be printable. Warning, I don't have time
> totest this right now.
> Jim
> 
> 
> On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter<
> bran.c...@gmail.com> wrote:Dear List,
> Is it possible to plot in R in "real" units? I would like to draw
> aplot on A4 paper, where 1 plot unit would be a mm in reality.
> Issomething like that possible? I would also like to be able to scale
> theplot in x and y direction.Background: For a project I would have
> to draw around 65 fast sketchesof elevation courves.
> Copied from here, due to no answer: 
> https://stackoverflow.com/questions/50606797/plot-in-real-units-mm
> Thank you!
> __r-h...@r-project.org
> mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the
> posting guide http://www.R-project.org/posting-guide.htmland 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] Plot function: hourly data and x-axis

2018-08-09 Thread Jeff Newmiller
Pre-process your data into per-day or per-month records, then plot it. There 
are many ways to do this... for example, base R has the aggregate function, and 
the dplyr package has the group_by/summarise functions, and the data.table 
package can do this as well (read the vignettes).

All of these techniques require that you learn how to deal with timestamps 
using one or more of the time classes. The most common of these can be 
introduced by reading

?DateTimeClasses

and/or reading some of the fine blogs online regarding this topic. Note that 
the trunc.POSIXt function offers one way to identify which time interval each 
record of your data belongs to.

If you need more assistance, read the Posting Guide and create a reproducible 
example similar to the data you are working with, and be sure to post it using 
plain text so it does not get corrupted in the mailing list.

On August 9, 2018 7:51:19 AM PDT, Edoardo Silvestri 
 wrote:
>Hi all,
>I have a little problem with plot function..
>I have an hourly dataset and I would like plot a variable with x-axis
>based
>on daily or monthly frequency, just to have a better visualization and
>avoid on x-axis all hours of the dataset.
>
>Do you know what is the solution?
>Thanks
>Edo
>
>   [[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.


Re: [R] Plot function: hourly data and x-axis

2018-08-09 Thread MacQueen, Don via R-help
Normally, one turns off the x-axis tick marks and labels by supplying   
xaxt='n'  in the plot() call, and then adds a customized x-axis using the 
axis() function.

But without more information, little help can be provided (a vague question 
receives a vague answer).

I'd suggest reviewing the posting guide and other advice shown at the bottom of 
every email sent by R-help.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 8/9/18, 7:51 AM, "R-help on behalf of Edoardo Silvestri" 
 wrote:

Hi all,
I have a little problem with plot function..
I have an hourly dataset and I would like plot a variable with x-axis based
on daily or monthly frequency, just to have a better visualization and
avoid on x-axis all hours of the dataset.

Do you know what is the solution?
Thanks
Edo

[[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] Plot Rclimdex or Climpact map with R

2018-07-30 Thread ouedraogo_agathe via R-help
For example the packages compute some indices let's say total precipitation 
(annua). So i ll have for each station a table representing annual totals with 
the trend slope. So i would like to put them on a map ( a county in Kenya) so 
that i can easily see the trend spatially.



Sent from my Samsung Galaxy smartphone.
 Original message From: Jim Lemon  Date: 
7/31/18  02:53  (GMT+03:00) To: ouedraogo_agathe  
Cc: r-help mailing list  Subject: Re: [R] Plot Rclimdex 
or Climpact map with R 
Hi Agathe,
You can start with the "maps" package:

# in an R session
install.packages("maps")
# assume you want a simple map containing France
map("world",xlim=c(-6.0,9.6),ylim=c(42,51.5))

then plot your data by the coordinates of the stations. You will
probably want to plot graphical elements to represent your data
values. There are a number of ways to represent more than one value at
a point with various combinations of shape, size, color and so on.
Perhaps with more information about what you want to display I could
be more specific.

Jim


On Tue, Jul 31, 2018 at 1:18 AM, ouedraogo_agathe via R-help
 wrote:
> HelloI am using Rclimdex and Climpact packages to compute some indices. 
> Having the location of all my stations I wish to plot the resultats on a map. 
> Is there a way to simply do it from the packages or how to do it for someone 
> who does not master R software?thanks
>
> Sent from my Samsung Galaxy smartphone.
> [[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.


Re: [R] Plot Rclimdex or Climpact map with R

2018-07-30 Thread Jim Lemon
Hi Agathe,
You can start with the "maps" package:

# in an R session
install.packages("maps")
# assume you want a simple map containing France
map("world",xlim=c(-6.0,9.6),ylim=c(42,51.5))

then plot your data by the coordinates of the stations. You will
probably want to plot graphical elements to represent your data
values. There are a number of ways to represent more than one value at
a point with various combinations of shape, size, color and so on.
Perhaps with more information about what you want to display I could
be more specific.

Jim


On Tue, Jul 31, 2018 at 1:18 AM, ouedraogo_agathe via R-help
 wrote:
> HelloI am using Rclimdex and Climpact packages to compute some indices. 
> Having the location of all my stations I wish to plot the resultats on a map. 
> Is there a way to simply do it from the packages or how to do it for someone 
> who does not master R software?thanks
>
> Sent from my Samsung Galaxy smartphone.
> [[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] Plot Rect Transparency

2018-07-27 Thread Martin Maechler
> Duncan Murdoch 
> on Thu, 28 Jun 2018 20:57:19 -0400 writes:

> On 28/06/2018 5:29 PM, Jeff Reichman wrote:
>> R-Help
>> 
>> 
>> 
>> Is there a way to make a rectangle transparent (alpha=0.1??)
>> 
>> 
>> 
>> plot(c(100, 200), c(300, 450), type= "n", xlab = "", ylab = "")
>> 
>> rect(110, 300, 175, 350, density = 5, border = "red")
>> 
>> 
>> 
>> Can't figure out how to take the changepoint function results and plot in
>> ggplot2 so I can just simply add rectangles to the plot function, but I 
need
>> to make transparent and there doesn't seem to be an alpha option.

> Alpha is part of the colour spec.  For example,

> rect(110, 300, 175, 350, density = 5, border = rgb("red")


> rect(110, 300, 175, 350, density = 5, border = rgb(red=1, green=0, 
> blue=0, alpha=0.1))

> I'm not sure what is the quickest way to work out the rgb values for a 
> named colour (col2rgb can do it, but not in a convenient format) if you 
> want to add alpha to it.

IIUC, it is adjustcolor() you were thinking of.  It had been
created to do that and more. 

I'm using that "all the time" nowadays in my graphics code,
e.g.,

> adjustcolor("red", 2/3)
[1] "#FFAA"

__
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 Rect Transparency

2018-06-28 Thread Jeff Reichman
Duncan 

Thanks I was able to find it in the help doc.

x <- c(1,2,4,6,8,9,10,12,13,14,18,20)
y <- c(4,5,3,6,7,4,8,9,12,4,7,5)

mydata <- data.frame(x,y)

plot(mydata)
rect(5,0,8,8, col=rgb(0,1,0,alpha=0.2), border=F)

-Original Message-
From: Duncan Murdoch  
Sent: Thursday, June 28, 2018 7:57 PM
To: reichm...@sbcglobal.net; R-help@r-project.org
Subject: Re: [R] Plot Rect Transparency

On 28/06/2018 5:29 PM, Jeff Reichman wrote:
> R-Help
> 
>   
> 
> Is there a way to make a rectangle transparent (alpha=0.1??)
> 
>   
> 
>plot(c(100, 200), c(300, 450), type= "n", xlab = "", ylab = "")
> 
> rect(110, 300, 175, 350, density = 5, border = "red")
> 
>   
> 
> Can't figure out how to take the changepoint function results and plot 
> in
> ggplot2 so I can just simply add rectangles to the plot function, but 
> I need to make transparent and there doesn't seem to be an alpha option.

Alpha is part of the colour spec.  For example,

rect(110, 300, 175, 350, density = 5, border = rgb("red")


rect(110, 300, 175, 350, density = 5, border = rgb(red=1, green=0, blue=0, 
alpha=0.1))

I'm not sure what is the quickest way to work out the rgb values for a named 
colour (col2rgb can do it, but not in a convenient format) if you want to add 
alpha to it.

Duncan Murdoch

__
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 Rect Transparency

2018-06-28 Thread Duncan Murdoch

On 28/06/2018 5:29 PM, Jeff Reichman wrote:

R-Help

  


Is there a way to make a rectangle transparent (alpha=0.1??)

  


   plot(c(100, 200), c(300, 450), type= "n", xlab = "", ylab = "")

rect(110, 300, 175, 350, density = 5, border = "red")

  


Can't figure out how to take the changepoint function results and plot in
ggplot2 so I can just simply add rectangles to the plot function, but I need
to make transparent and there doesn't seem to be an alpha option.


Alpha is part of the colour spec.  For example,

rect(110, 300, 175, 350, density = 5, border = rgb("red")


rect(110, 300, 175, 350, density = 5, border = rgb(red=1, green=0, 
blue=0, alpha=0.1))


I'm not sure what is the quickest way to work out the rgb values for a 
named colour (col2rgb can do it, but not in a convenient format) if you 
want to add alpha to it.


Duncan Murdoch

__
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 in real unit (1:1)

2018-06-07 Thread Eik Vettorazzi
How about this:

in2mm<-25.4 # scale factor to convert inches to mm

pdf("test.pdf",width=8.3,height=11.7)
pin<-par("pin")
plot(c(0,pin[1]*in2mm),c(0,pin[2]*in2mm), type="n", xaxs="i", yaxs="i")
lines(c(10,10),c(0,10))
text(11,5,"1 cm", adj=0)

lines(c(0,40),c(20,20))
text(20,24,"4 cm")

polygon(c(50,50,70,70),c(50,70,70,50))
text(60,60,"2x2 cm")
dev.off()

cheers

Am 06.06.2018 um 16:00 schrieb Christian Brandstätter:
> Dear List, 
> 
> Is it possible to plot in R in "real" units? I would like to draw a
> plot on A4 paper, where 1 plot unit would be a mm in reality. Is
> something like that possible? I would also like to be able to scale the
> plot in x and y direction. 
> Background: For a project I would have to draw around 65 fast sketches
> of elevation courves. 
> 
> Copied from here, due to no answer: https://stackoverflow.com/questions
> /50606797/plot-in-real-units-mm
> 
> Thank you!
> 
> __
> 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.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

SAVE PAPER - THINK BEFORE PRINTING
__
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 in real unit (1:1)

2018-06-06 Thread Brandstätter Christian
Thanks a lot!

Jim Lemon  schrieb am Do., 7. Juni 2018, 06:13:

> Hi Christian,
> Well, it almost worked. I suspect that the postscript device adds some
> padding to account for the printable area, so with a bit of
> experimentation, The following example seems to do what you want. When
> I printed the resulting file from the GIMP, the box and diamond were
> the correct dimensions.
>
> postscript("test.ps",paper="a4",horizontal=FALSE)
> par(mai=c(1.713,0,1.713,0),xaxs="i",yaxs="i")
> plot(0,type="n",xlim=c(0,190),ylim=c(0,190),xlab="",axes=FALSE)
> segments(c(0,95),c(95,0),c(190,95),c(95,190))
> segments(c(45,95,145,95),c(95,145,95,45),
>  c(95,145,95,45),c(145,95,45,95))
> box()
> dev.off()
>
> Jim
>
> On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon  wrote:
> > Hi Christian,
> > When I have to do something like this, I usually write it in
> > Postscript using this:
> >
> > /def mm 2.8346 mul
> >
> > that converts a dimension in mm to points (1/72 inch). However, this
> > won't work in R. It may be possible to set up the device like this:
> >
> > postscript("myfile.ps",paper="a4")
> > par(mar=c(0,0,0,0))
> > # generate a blank plot
> > plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE)
> > # display lines, etc. in mm with 0,0 at the bottom left
> > dev.off()
> >
> > The resulting file should be printable. Warning, I don't have time to
> > test this right now.
> >
> > Jim
> >
> >
> >
> > On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter
> >  wrote:
> >> Dear List,
> >>
> >> Is it possible to plot in R in "real" units? I would like to draw a
> >> plot on A4 paper, where 1 plot unit would be a mm in reality. Is
> >> something like that possible? I would also like to be able to scale the
> >> plot in x and y direction.
> >> Background: For a project I would have to draw around 65 fast sketches
> >> of elevation courves.
> >>
> >> Copied from here, due to no answer: https://stackoverflow.com/questions
> >> /50606797/plot-in-real-units-mm
> >>
> >> Thank you!
> >>
> >> __
> >> 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] Plot in real unit (1:1)

2018-06-06 Thread Jim Lemon
Hi Christian,
Well, it almost worked. I suspect that the postscript device adds some
padding to account for the printable area, so with a bit of
experimentation, The following example seems to do what you want. When
I printed the resulting file from the GIMP, the box and diamond were
the correct dimensions.

postscript("test.ps",paper="a4",horizontal=FALSE)
par(mai=c(1.713,0,1.713,0),xaxs="i",yaxs="i")
plot(0,type="n",xlim=c(0,190),ylim=c(0,190),xlab="",axes=FALSE)
segments(c(0,95),c(95,0),c(190,95),c(95,190))
segments(c(45,95,145,95),c(95,145,95,45),
 c(95,145,95,45),c(145,95,45,95))
box()
dev.off()

Jim

On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon  wrote:
> Hi Christian,
> When I have to do something like this, I usually write it in
> Postscript using this:
>
> /def mm 2.8346 mul
>
> that converts a dimension in mm to points (1/72 inch). However, this
> won't work in R. It may be possible to set up the device like this:
>
> postscript("myfile.ps",paper="a4")
> par(mar=c(0,0,0,0))
> # generate a blank plot
> plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE)
> # display lines, etc. in mm with 0,0 at the bottom left
> dev.off()
>
> The resulting file should be printable. Warning, I don't have time to
> test this right now.
>
> Jim
>
>
>
> On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter
>  wrote:
>> Dear List,
>>
>> Is it possible to plot in R in "real" units? I would like to draw a
>> plot on A4 paper, where 1 plot unit would be a mm in reality. Is
>> something like that possible? I would also like to be able to scale the
>> plot in x and y direction.
>> Background: For a project I would have to draw around 65 fast sketches
>> of elevation courves.
>>
>> Copied from here, due to no answer: https://stackoverflow.com/questions
>> /50606797/plot-in-real-units-mm
>>
>> Thank you!
>>
>> __
>> 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.


  1   2   3   4   5   6   7   8   9   10   >