Re: [R] ggplot2 with an arbitrary number of curves from geom_function + legend?

2022-02-27 Thread Jeff Newmiller
Well, the ggplot2 CRAN page [1] points people to [2], which in turn points out 
that support can be found on the RStudio community forums and StackOverflow, so 
there is a path from here (where contributed packages are off-topic per the 
Posting Guide) to getting help.

I will point out that the canonical solution is definitely to put all of your 
data into one long-form data frame and use a factor column to distinguish 
aesthetics (one google result is [3]) ... loops really don't work well to add 
layers to ggplots.

But yes, if you have further questions on a contributed package, do follow the 
breadcrumbs from CRAN for sources of help, and come back when your question is 
about the R language.

[1] https://cran.r-project.org/web/packages/ggplot2/index.html
[2] https://ggplot2.tidyverse.org/
[3] 
https://stackoverflow.com/questions/64523271/how-to-insert-a-legend-in-a-ggplot-with-multiple-time-series

On February 27, 2022 10:00:31 PM PST, Avi Gross via R-help 
 wrote:
>I would reply but since ggplot was mentioned, I must abstain. ;-)
>
>I will say that you can use ggplot in a loop in some cases if you do this:
>
>p <- ggplot(...) + ...
>
>Then you can in your loop keep adding to p as in:
>
>p <- p + geom_whatever() + ...
>
>You do at some point need to make p print itself and generate a graph. Until 
>then, it can be amended, albeit some changes undo or overwrite earlier ones if 
>not done carefully.
>
>Having said all that, there is often a way to do a kind of looping within 
>ggplot by say grouping your data and having it draw things grouped, or say 
>making multiple vertical (or horizontal) lines by supplying a vector of 
>positions.
>
>But as noted, this is not considered a good place by some to discuss this, so 
>forget I said anything.
>
>
>
>
>-Original Message-
>From: Michael Bonert 
>To: r-help@r-project.org 
>Sent: Sun, Feb 27, 2022 8:02 pm
>Subject: [R] ggplot2 with an arbitrary number of curves from geom_function + 
>legend?
>
>Dear R-help,
>
>I am trying to create a ggplot with an arbitrary number of curves + legend.
>
>The plot should contain:
>1. data points + a line that is either user defined *or* represents the median 
>of the data points
>2. an arbitrary number of confidence intervals (CIs) around the line, where 
>the CIs are defined by a function
>
>#1: this is easy enough
>#2: I don't know how to combine this with #1
>
>I can write #2 as a loop (see below) but it is then seems to be impossible to 
>get ggplot to do a proper legend.
>
>The challenge I have seems similar to this problem:
>https://stackoverflow.com/questions/12169289/ggplot2-fail-to-apply-color-with-scale-fill-manual-inside-a-loop
>
>I read that one should not use a loop with ggplot ( 
>https://stackoverflow.com/questions/62603533/adding-ggplot2-legend-with-many-lines-using-for-loop
> ).
>(Interesting: there are probably a half dozen posts on ggplot + loops floating 
>around on the web.  I do not feel alone in my problem... but I also do not 
>think I am close to solving it.)
>(As a user of GNU/Octave ( octave.org ) using a loop seems the intuitive 
>solution. In GNU/Octave one does a "hold on" and then plots however many 
>lines/objects one wants within a figure.)
>
>Is there a way to freeze the 'scale_colour_manual' attribute?
>(The way the code is written: the colour scale seems to be overwritten with 
>the 'fp=fp ...' statement)
>(I have gotten the message: "Scale for 'colour' is already present. Adding 
>another scale for 'colour',
>which will replace the existing scale.")
>
>Loop aside:
>Is there a way to elegantly pipe an arbitrary number of 'geom_function' calls 
>to the 'ggplot'?
>(I wondered whether the '%>%' operator in 'dplyr' is a possible solution -- as 
>suggested here:
>https://stackoverflow.com/questions/30655364/ggplot2-getting-a-color-legend-to-appear-using-stat-function-in-a-for-loop
> )
>
>
>I could write code to generate a data frame that has the data points and 
>points for arbitrary curves; however,
>this would necessitate writing a function that replicates 'geom_function'.
>
>Is there a way to generate the text string and then execute it?
>( 
>https://stackoverflow.com/questions/1743698/evaluate-expression-given-as-a-string
> )
>(In my humble opinion: this would be a hack.)
>
>Is there a way to generate a legend with 'override.aes'?
>( 
>https://www.r-bloggers.com/2020/07/controlling-legend-appearance-in-ggplot2-with-override-aes/
> )
>
>
>Below is the attempt at creating a legend:
>~~
>  # plot the data points
>  fp = ggplot(df,aes(x=x_var, y=y_var), colour4labels[num_of_funnels+2]) + 
>geom_point(size=4, na.rm = TRUE, alpha = 0.75) + 
>theme(legend.position="bottom") + scale_color_manual(labels = legend_labels, 
>values = colour4labels) + guides(color=guide_legend("Control Limits")) + 
>geom_hline(aes(yintercept = funnel_centre_line, colour = 
>colour4labels[num_of_funnels+1]), linetype = 2) + xlab(x_label) + 
>ylab(y_label) + ggtitle(plot_title) + 
>theme(axis.title=element_text(face

Re: [R] ggplot2 with an arbitrary number of curves from geom_function + legend?

2022-02-27 Thread Avi Gross via R-help
I would reply but since ggplot was mentioned, I must abstain. ;-)

I will say that you can use ggplot in a loop in some cases if you do this:

p <- ggplot(...) + ...

Then you can in your loop keep adding to p as in:

p <- p + geom_whatever() + ...

You do at some point need to make p print itself and generate a graph. Until 
then, it can be amended, albeit some changes undo or overwrite earlier ones if 
not done carefully.

Having said all that, there is often a way to do a kind of looping within 
ggplot by say grouping your data and having it draw things grouped, or say 
making multiple vertical (or horizontal) lines by supplying a vector of 
positions.

But as noted, this is not considered a good place by some to discuss this, so 
forget I said anything.




-Original Message-
From: Michael Bonert 
To: r-help@r-project.org 
Sent: Sun, Feb 27, 2022 8:02 pm
Subject: [R] ggplot2 with an arbitrary number of curves from geom_function + 
legend?

Dear R-help,

I am trying to create a ggplot with an arbitrary number of curves + legend.

The plot should contain:
1. data points + a line that is either user defined *or* represents the median 
of the data points
2. an arbitrary number of confidence intervals (CIs) around the line, where the 
CIs are defined by a function

#1: this is easy enough
#2: I don't know how to combine this with #1

I can write #2 as a loop (see below) but it is then seems to be impossible to 
get ggplot to do a proper legend.

The challenge I have seems similar to this problem:
https://stackoverflow.com/questions/12169289/ggplot2-fail-to-apply-color-with-scale-fill-manual-inside-a-loop

I read that one should not use a loop with ggplot ( 
https://stackoverflow.com/questions/62603533/adding-ggplot2-legend-with-many-lines-using-for-loop
 ).
(Interesting: there are probably a half dozen posts on ggplot + loops floating 
around on the web.  I do not feel alone in my problem... but I also do not 
think I am close to solving it.)
(As a user of GNU/Octave ( octave.org ) using a loop seems the intuitive 
solution. In GNU/Octave one does a "hold on" and then plots however many 
lines/objects one wants within a figure.)

Is there a way to freeze the 'scale_colour_manual' attribute?
(The way the code is written: the colour scale seems to be overwritten with the 
'fp=fp ...' statement)
(I have gotten the message: "Scale for 'colour' is already present. Adding 
another scale for 'colour',
which will replace the existing scale.")

Loop aside:
Is there a way to elegantly pipe an arbitrary number of 'geom_function' calls 
to the 'ggplot'?
(I wondered whether the '%>%' operator in 'dplyr' is a possible solution -- as 
suggested here:
https://stackoverflow.com/questions/30655364/ggplot2-getting-a-color-legend-to-appear-using-stat-function-in-a-for-loop
 )


I could write code to generate a data frame that has the data points and points 
for arbitrary curves; however,
this would necessitate writing a function that replicates 'geom_function'.

Is there a way to generate the text string and then execute it?
( 
https://stackoverflow.com/questions/1743698/evaluate-expression-given-as-a-string
 )
(In my humble opinion: this would be a hack.)

Is there a way to generate a legend with 'override.aes'?
( 
https://www.r-bloggers.com/2020/07/controlling-legend-appearance-in-ggplot2-with-override-aes/
 )


Below is the attempt at creating a legend:
~~
  # plot the data points
  fp = ggplot(df,aes(x=x_var, y=y_var), colour4labels[num_of_funnels+2]) + 
geom_point(size=4, na.rm = TRUE, alpha = 0.75) + 
theme(legend.position="bottom") + scale_color_manual(labels = legend_labels, 
values = colour4labels) + guides(color=guide_legend("Control Limits")) + 
geom_hline(aes(yintercept = funnel_centre_line, colour = 
colour4labels[num_of_funnels+1]), linetype = 2) + xlab(x_label) + ylab(y_label) 
+ ggtitle(plot_title) + theme(axis.title=element_text(face="bold"), plot.title 
= element_text(size = 14, face = "bold", hjust = 0.5))

  # add funnel plot curves (limits)
  for (ci_ctr in 1:length(limits)) {
    if (ci_ctr==1) {
      fp = fp + geom_function(fun = calc_fpc, args = list(ci_or_alpha = 
limits[ci_ctr], probability = funnel_centre_line, upper_or_lower = 1, trunc_val 
= 0), aes(colour = colour4labels[ci_ctr]), size = 1.1, na.rm = TRUE, linetype = 
5) + geom_function(fun = calc_fpc, args = list(ci_or_alpha = limits[ci_ctr], 
probability = funnel_centre_line, upper_or_lower = 2, trunc_val = 0), 
aes(colour = colour4labels[ci_ctr]), size = 1.1, na.rm = TRUE, linetype = 5) + 
theme(legend.position="bottom") + scale_color_manual(labels = legend_labels, 
values = colour4labels) + guides(color=guide_legend("Control Limits"))

    } else if (ci_ctr==2) {
      fp = fp + geom_function(fun = calc_fpc, args = list(ci_or_alpha = 
limits[ci_ctr], probability = funnel_centre_line, upper_or_lower = 1, trunc_val 
= 0), aes(colour = colour4labels[ci_ctr]), size = 1.3, na.rm = TRUE) + 
geom_function(fun = calc_fpc, args = list(ci_or_al

Re: [R] tidying up

2022-02-27 Thread Bert Gunter
For those wishing to make changes to r-help or seeking info on the R
mailing lists in general, please consult:
https://www.r-project.org/mail.html   You may wish to cc Martin
Maechler on any proposals for change, as he is one of the maintainers
-- or at least can contact the maintainers -- of these lists. Nothing
will change if they don't change it. (I believe he does monitor the
traffic here, though.)

Note the first line on that mailing list page: "**Please** read the
instructions below and the posting guide before sending anything to
any mailing list!" Still THE definitive statement of proper use of
these lists, alas often more honored in the breach than the
observance.

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 )

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, Feb 27, 2022 at 4:07 PM Micha Silver  wrote:
>
>
> On 27/02/2022 21:34, Avi Gross via R-help wrote:
> > This mailing list seems to steadily get messages that some see as not 
> > relevant to this forum. In particular, some see it as wrong to bring up 
> > some things here and keep reminding people of some ground rules.
> > So I want to know, briefly, if it is reasonable to ask a person with a 
> > question or problem to reproduce their problem another way. If using 
> > RSTUDIO or one of many IDE, can they run the code on a naked R interpreter 
> > by sourcing the file or copying it in or typing it anew, or perhaps using 
> > IDLE which comes by default with many installations of R? If using a 
> > library (which I like so I am not really in agreement about the 
> > unsuitability) like the tidyverse which is free and available to all even 
> > if loosely associated with the RSTUDIO folks and that can be run on any 
> > version of R that I am aware of, then some questions may still be fair if 
> > they are really about more general R issues as much of the rest of the code 
> > may be base R and may be the cause of whatever issue is being reported. 
> > And, some simple requests like pointing out a missing comma, ...
> >
> > I have stated my thought before and it boils down to the reality that there 
> > are some things about earlier versions of R that were far from perfect or 
> > complete and a little healthy competition is not a bad thing and may help 
> > base R evolve. Not everything in the tidyverse is better and it keeps 
> > evolving and deprecating older features, but it cannot really be ignored 
> > any longer. If you apply for a job at some company as something of an R 
> > expert, you may well be asked by all kinds of people about their programs 
> > that use the tidyverse for help or to help them solve a problem. You don't 
> > have to like it, but if you cannot read it, you no longer are really 
> > qualified in many places.
>
>
> There's an easy way to test this:
>
> There are already several r-sig-* lists. I might suggest to create a new
> r-sig-base list. Those who want to ask and answer issues dealing with
> base R only would be invited to migrate to that list. Then this current
> list could be broadened to address questions about R as well as other
> (popular) packages.
>
>
> Yes, the list might get flooded with questions about obscure packages,
> or about statistics. But if no one answers, posters will eventually
> learn to go straight to the package maintainers, or elsewhere. And,
> along the way, it would save the numerous "irrelevant, off topic..."
> responses that you refer to.
>
>
> Kind regards,
>
>
> > Ask yourself if a language like R was created from scratch, what graphics 
> > might be built into the base distribution? Would you rather have lattice or 
> > ggplot or perhaps both as well as base R graphics? Would you make many of 
> > the built-in functions more consistent, so for instance, the data being 
> > worked on would be the first argument whenever possible?
> >
> > One reason there are so many packages is not so much due to the superiority 
> > of R but because people find it lacks quite a bit. Much of that should not 
> > be included, of course, if R is meant to be somewhat on the lean side, and 
> > yes, packages are a deliberate way to extend it when needed. But when 
> > people use it and think they are programming in 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.
>
> --
> Micha Silver
> Ben Gurion Univ.
> Sde Boker, Remote Sensing Lab
> cell: +972-523-665918
> https://orcid.org/-0002-1128-1325
>
> __
> 

Re: [R] tidying up

2022-02-27 Thread Jeff Newmiller
FWIW my brief answer to your brief question is "of course" it is okay. The real 
problem however are the questions that can only be answered by people with 
detailed understanding of non-R-related issues, such as the workings of the 
custom interactive graphics device used by RStudio or the broken behavior of 
some random GitHub-hosted package. There are a continuum of possible "degrees 
of relevance" that a question can have to the topic of a given discussion area 
(e.g. web forum or mailing list). The people who don't use RStudio don't gain 
benefit from wading through discussions that only have relevance to that 
tangential topic, and the more of that there is the lower the signal-to-noise 
ratio is from their perspective... and the sooner they leave. Ideally we will 
be kind in our redirection of the uninitiated, but an actual answer may not be 
feasible here... going elsewhere for a specific question should not be viewed 
as a negative outcome.

Since there are various interpretations of where the line should be drawn, it 
is best that it be drawn as the discussion area charter says it should... in 
this case, about R, the language. It is pretty explicit that discussion of 
contributed packages is not on-topic... presumably because allowing that can 
easily lead to highly arcane discussions that don't necessarily help people 
understand the R language better.

I think the existence of contributed packages and various development tools is 
hugely beneficial and I depend on many of them... but that doesn't 
automatically give any of them carte blanche to become actual topics of 
discussion here.

On February 27, 2022 11:34:33 AM PST, Avi Gross via R-help 
 wrote:
>This mailing list seems to steadily get messages that some see as not relevant 
>to this forum. In particular, some see it as wrong to bring up some things 
>here and keep reminding people of some ground rules.
>
>So I want to know, briefly, if it is reasonable to ask a person with a 
>question or problem to reproduce their problem another way. If using RSTUDIO 
>or one of many IDE, can they run the code on a naked R interpreter by sourcing 
>the file or copying it in or typing it anew, or perhaps using IDLE which comes 
>by default with many installations of R? If using a library (which I like so I 
>am not really in agreement about the unsuitability) like the tidyverse which 
>is free and available to all even if loosely associated with the RSTUDIO folks 
>and that can be run on any version of R that I am aware of, then some 
>questions may still be fair if they are really about more general R issues as 
>much of the rest of the code may be base R and may be the cause of whatever 
>issue is being reported. And, some simple requests like pointing out a missing 
>comma, ...
>
>I have stated my thought before and it boils down to the reality that there 
>are some things about earlier versions of R that were far from perfect or 
>complete and a little healthy competition is not a bad thing and may help base 
>R evolve. Not everything in the tidyverse is better and it keeps evolving and 
>deprecating older features, but it cannot really be ignored any longer. If you 
>apply for a job at some company as something of an R expert, you may well be 
>asked by all kinds of people about their programs that use the tidyverse for 
>help or to help them solve a problem. You don't have to like it, but if you 
>cannot read it, you no longer are really qualified in many places.
>
>Ask yourself if a language like R was created from scratch, what graphics 
>might be built into the base distribution? Would you rather have lattice or 
>ggplot or perhaps both as well as base R graphics? Would you make many of the 
>built-in functions more consistent, so for instance, the data being worked on 
>would be the first argument whenever possible? 
>
>One reason there are so many packages is not so much due to the superiority of 
>R but because people find it lacks quite a bit. Much of that should not be 
>included, of course, if R is meant to be somewhat on the lean side, and yes, 
>packages are a deliberate way to extend it when needed. But when people use it 
>and think they are programming in 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.

-- 
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] tidying up

2022-02-27 Thread Avi Gross via R-help
Indeed, Jim, the hopeful purpose of interactions here is to help people without 
doing the job for them. As you note, sometimes it is help in getting them to 
formulate what they are trying to do and maybe see the resolution on their own, 
or give enough info that others can troubleshoot.

I have dealt with people on and off forums like this who know very little and 
have done some rudimentary search and found something they hope is helpful and 
then get stuck. Some have no actual interest in learning R or Python or 
anything and see it as a one-time thing. For them, any sustained interaction is 
just frustrating. Others may want a tutor, albeit mahy of us here are not 
willing or able to provide endless hours to volunteer. And some, may be better 
off spending the money to hire someone and I assume there are places they can 
be directed.




-Original Message-
From: Jim Lemon 
To: Avi Gross 
Cc: r-help@r-project.org 
Sent: Sun, Feb 27, 2022 4:52 pm
Subject: Re: [R] tidying up


Hi Avi,
I just sent in an answer to a very simple question. In many cases it
seems to me that the real problem isn't apparent from the request.
ektaraK appears to have almost no experience with R (sorry if I'm
wrong). A person in this position may sort of know what they want to
do but do not know how to ask the question. What's a reproducible
example? So I often submit really dumb looking answers that show the
person how to ask the question. If I'm successful, the OP learns how
to do some basic operation, but also learns how to ask the next
question. Until they get there, most responses just give them a typing
exercise.

Jim


On Mon, Feb 28, 2022 at 6:35 AM Avi Gross via R-help
 wrote:
>
> This mailing list seems to steadily get messages that some see as not 
> relevant to this forum. In particular, some see it as wrong to bring up some 
> things here and keep reminding people of some ground rules.
>
> So I want to know, briefly, if it is reasonable to ask a person with a 
> question or problem to reproduce their problem another way. If using RSTUDIO 
> or one of many IDE, can they run the code on a naked R interpreter by 
> sourcing the file or copying it in or typing it anew, or perhaps using IDLE 
> which comes by default with many installations of R? If using a library 
> (which I like so I am not really in agreement about the unsuitability) like 
> the tidyverse which is free and available to all even if loosely associated 
> with the RSTUDIO folks and that can be run on any version of R that I am 
> aware of, then some questions may still be fair if they are really about more 
> general R issues as much of the rest of the code may be base R and may be the 
> cause of whatever issue is being reported. And, some simple requests like 
> pointing out a missing comma, ...
>
> I have stated my thought before and it boils down to the reality that there 
> are some things about earlier versions of R that were far from perfect or 
> complete and a little healthy competition is not a bad thing and may help 
> base R evolve. Not everything in the tidyverse is better and it keeps 
> evolving and deprecating older features, but it cannot really be ignored any 
> longer. If you apply for a job at some company as something of an R expert, 
> you may well be asked by all kinds of people about their programs that use 
> the tidyverse for help or to help them solve a problem. You don't have to 
> like it, but if you cannot read it, you no longer are really qualified in 
> many places.
>
> Ask yourself if a language like R was created from scratch, what graphics 
> might be built into the base distribution? Would you rather have lattice or 
> ggplot or perhaps both as well as base R graphics? Would you make many of the 
> built-in functions more consistent, so for instance, the data being worked on 
> would be the first argument whenever possible?
>
> One reason there are so many packages is not so much due to the superiority 
> of R but because people find it lacks quite a bit. Much of that should not be 
> included, of course, if R is meant to be somewhat on the lean side, and yes, 
> packages are a deliberate way to extend it when needed. But when people use 
> it and think they are programming in 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.

__
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] tidying up

2022-02-27 Thread Jim Lemon
Hi Avi,
I just sent in an answer to a very simple question. In many cases it
seems to me that the real problem isn't apparent from the request.
ektaraK appears to have almost no experience with R (sorry if I'm
wrong). A person in this position may sort of know what they want to
do but do not know how to ask the question. What's a reproducible
example? So I often submit really dumb looking answers that show the
person how to ask the question. If I'm successful, the OP learns how
to do some basic operation, but also learns how to ask the next
question. Until they get there, most responses just give them a typing
exercise.

Jim

On Mon, Feb 28, 2022 at 6:35 AM Avi Gross via R-help
 wrote:
>
> This mailing list seems to steadily get messages that some see as not 
> relevant to this forum. In particular, some see it as wrong to bring up some 
> things here and keep reminding people of some ground rules.
>
> So I want to know, briefly, if it is reasonable to ask a person with a 
> question or problem to reproduce their problem another way. If using RSTUDIO 
> or one of many IDE, can they run the code on a naked R interpreter by 
> sourcing the file or copying it in or typing it anew, or perhaps using IDLE 
> which comes by default with many installations of R? If using a library 
> (which I like so I am not really in agreement about the unsuitability) like 
> the tidyverse which is free and available to all even if loosely associated 
> with the RSTUDIO folks and that can be run on any version of R that I am 
> aware of, then some questions may still be fair if they are really about more 
> general R issues as much of the rest of the code may be base R and may be the 
> cause of whatever issue is being reported. And, some simple requests like 
> pointing out a missing comma, ...
>
> I have stated my thought before and it boils down to the reality that there 
> are some things about earlier versions of R that were far from perfect or 
> complete and a little healthy competition is not a bad thing and may help 
> base R evolve. Not everything in the tidyverse is better and it keeps 
> evolving and deprecating older features, but it cannot really be ignored any 
> longer. If you apply for a job at some company as something of an R expert, 
> you may well be asked by all kinds of people about their programs that use 
> the tidyverse for help or to help them solve a problem. You don't have to 
> like it, but if you cannot read it, you no longer are really qualified in 
> many places.
>
> Ask yourself if a language like R was created from scratch, what graphics 
> might be built into the base distribution? Would you rather have lattice or 
> ggplot or perhaps both as well as base R graphics? Would you make many of the 
> built-in functions more consistent, so for instance, the data being worked on 
> would be the first argument whenever possible?
>
> One reason there are so many packages is not so much due to the superiority 
> of R but because people find it lacks quite a bit. Much of that should not be 
> included, of course, if R is meant to be somewhat on the lean side, and yes, 
> packages are a deliberate way to extend it when needed. But when people use 
> it and think they are programming in 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.

__
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&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=JeHylIm3ibHTYNZ-mLAAkF4JTrj_xyBnd0IQBZDJvV6HeovFeOLa5GwBe0LLBOwN&s=WJLtDEQ05d0kvlWFlrGCadjyBvwqCm_j37wsJ-CObyA&e=
> PLEASE do read the posting guide 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=JeHylIm3ibHTYNZ-mLAAkF4JTrj_xyBnd0IQBZDJvV6HeovFeOLa5GwBe0LLBOwN&s=QyEPln_51yStVY2Ec1hcAqygLeEh1CNf5JJT_vv1dto&e=
> 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.


[R] tidying up

2022-02-27 Thread Avi Gross via R-help
This mailing list seems to steadily get messages that some see as not relevant 
to this forum. In particular, some see it as wrong to bring up some things here 
and keep reminding people of some ground rules.

So I want to know, briefly, if it is reasonable to ask a person with a question 
or problem to reproduce their problem another way. If using RSTUDIO or one of 
many IDE, can they run the code on a naked R interpreter by sourcing the file 
or copying it in or typing it anew, or perhaps using IDLE which comes by 
default with many installations of R? If using a library (which I like so I am 
not really in agreement about the unsuitability) like the tidyverse which is 
free and available to all even if loosely associated with the RSTUDIO folks and 
that can be run on any version of R that I am aware of, then some questions may 
still be fair if they are really about more general R issues as much of the 
rest of the code may be base R and may be the cause of whatever issue is being 
reported. And, some simple requests like pointing out a missing comma, ...

I have stated my thought before and it boils down to the reality that there are 
some things about earlier versions of R that were far from perfect or complete 
and a little healthy competition is not a bad thing and may help base R evolve. 
Not everything in the tidyverse is better and it keeps evolving and deprecating 
older features, but it cannot really be ignored any longer. If you apply for a 
job at some company as something of an R expert, you may well be asked by all 
kinds of people about their programs that use the tidyverse for help or to help 
them solve a problem. You don't have to like it, but if you cannot read it, you 
no longer are really qualified in many places.

Ask yourself if a language like R was created from scratch, what graphics might 
be built into the base distribution? Would you rather have lattice or ggplot or 
perhaps both as well as base R graphics? Would you make many of the built-in 
functions more consistent, so for instance, the data being worked on would be 
the first argument whenever possible? 

One reason there are so many packages is not so much due to the superiority of 
R but because people find it lacks quite a bit. Much of that should not be 
included, of course, if R is meant to be somewhat on the lean side, and yes, 
packages are a deliberate way to extend it when needed. But when people use it 
and think they are programming in 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] Plots not showing up in the RStudio plot pane

2022-02-27 Thread Md. Moyazzem Hossain
Dear Jeff Newmiller

Thank you very much for your reply.

Take care.

Hossain


On Sat, Feb 26, 2022 at 10:30 PM Jeff Newmiller 
wrote:

> This mailing list is about R, not RStudio [1]. RStudio normally sets up
> the default graphics device to be their IDE device, but details as to why
> that behavior may be broken for you wouldn't normally be discussed here.
>
> FWIW if you are using some contributed package it may bypass the default
> graphics device setting... but you have not provided a reproducible example
> so no one else could know if that could be the problem.
>
> You may also have a `.Rprofile` R file in your home directory with some
> commands in it that could mess with your settings.
>
> [1] https://community.rstudio.com/
>
> On February 26, 2022 2:03:53 PM PST, "Md. Moyazzem Hossain" <
> hossai...@juniv.edu> wrote:
> >Dear R-experts,
> >
> >I hope that you are doing well.
> >
> >Whenever I use the plot command in RStudio, the plot is shown in a new
> >device window. I want the device to stay in the RStudio plot window in the
> >lower righthand corner.
> >
> >I have tried in the following way.
> >
> >1. I have used the dev.off() command. It just closes the window but when I
> >use the plot command then a new window opened again.
> >2. Tools->Global options->R Mark down In that phase select "window" from
> >that list in the "show output preview in:" then apply.
> >3. Tools > Global Options > Pane Layout, "Plots" is checked.
> >4. Update the RStudio.
> >
> >However, still have the same problem.
> >
> >I would be happy if anyone has any help to solve it.
> >Thanks in advance.
> >
> >Hossain
>
> --
> Sent from my phone. Please excuse my brevity.
>


-- 
Best Regards,
Md. Moyazzem Hossain
Associate Professor
Department of Statistics
Jahangirnagar University
Savar, Dhaka-1342, Bangladesh
Website: http://www.juniv.edu/teachers/hossainmm
Research: *[image: Google Scholar]
* | *ResearchGate
* | *ORCID iD
*

[[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] Plots not showing up in the RStudio plot pane

2022-02-27 Thread Edjabou Vincent
Hej
Try maybe: dev.off() before plotting.
Regards,

Vincent Edjabou
Mobile: +45 31 95 99 33
linkedin.com/vincent


Orcid: -0003-2849-6151



On Sat, Feb 26, 2022 at 11:04 PM Md. Moyazzem Hossain 
wrote:

> Dear R-experts,
>
> I hope that you are doing well.
>
> Whenever I use the plot command in RStudio, the plot is shown in a new
> device window. I want the device to stay in the RStudio plot window in the
> lower righthand corner.
>
> I have tried in the following way.
>
> 1. I have used the dev.off() command. It just closes the window but when I
> use the plot command then a new window opened again.
> 2. Tools->Global options->R Mark down In that phase select "window" from
> that list in the "show output preview in:" then apply.
> 3. Tools > Global Options > Pane Layout, "Plots" is checked.
> 4. Update the RStudio.
>
> However, still have the same problem.
>
> I would be happy if anyone has any help to solve it.
> Thanks in advance.
>
> Hossain
> --
> Best Regards,
> Md. Moyazzem Hossain
> Associate Professor
> Department of Statistics
> Jahangirnagar University
> Savar, Dhaka-1342, Bangladesh
> Website: http://www.juniv.edu/teachers/hossainmm
> Research: *[image: Google Scholar]
> * |
> *ResearchGate
> * | *ORCID iD
> *
>
> [[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.