Re: [R] graphics useRaster check_irregular definition for date or posix

2021-04-15 Thread Paul Murrell

Hi

On 15/04/21 7:27 pm, cda...@posteo.de wrote:

Hi Paul

Thanks for the FAQs related to the unwanted white lines. However, even 
if it is just the png/pdf viewer that causes the white lines, I would 
like to try to avoid them as much as possible, and setting useRaster to 
true does that.


Sure.  Fair enough.

My wish would be that I can use a date or POSIX* vector as x and/or y 
axis as it is without using some numerical values instead and then 
always need to take special care for the corresponding labels. 
Particularly for date/POSIX* objects this can be annoying. So the axes 
or their labels are not my problem, I just need the useRaster true or 
false decision to be consistent.


How do you deduce that the diff of the midpoints (i.e. the modifided x) 
is not "regular"? This, again, will be decided later in image.default() 
by check_irregular(), what brings us back to my initial post?


The problem is that the modification of 'x' for midpoints makes the 'x' 
irregular even if 'x' starts off as regular (when 'x' is a Date).


Paul


Cheers,
Chris

Am 15.04.2021 03:26 schrieb Paul Murrell:


Hi

Feeding R-help back in, in case my suggestions might be of use to someone else 
...

Thanks for the examples - so the main benefit you are looking for is the 
labelling on the axes (date labels) ?

If you are just trying to avoid the annoying white lines, it may just be your 
PNG/PDF viewer;  see ...

http://cran.stat.auckland.ac.nz/doc/FAQ/R-FAQ.html#Why-are-there-unwanted-borders  


Even so, making this work for date values for x/y seems like a useful thing.  
However, ...

Neither your "fix" nor my "fix" actually works for the example that you have provided.  
It just reveals another problem within image.default(), which is the calculation of "midpoints" ...

 if (length(x) > 1 && length(x) == nrow(z)) { # midpoints
 dx <- 0.5*diff(x)
 x <- c(x[1L] - dx[1L], x[-length(x)] + dx,
x[length(x)] + dx[length(x)-1])
 }

This calculation does NOT produce the desired result for "Date"s (the diff() of 
the resulting modified 'x' is no longer regular).

So this needs a bit more thought - let me know if you come up with a fix for 
that calculation before me :)

Paul

On 15/04/21 4:05 am,cda...@posteo.de    wrote:
Hi Paul Thanks for your answer. I just answer to you, I dont know if 
this is correct (also the maillist?) x <- y <- 
seq(as.Date("2020-1-1"), as.Date("2020-12-31"), l=12) z <- 
array(rnorm(length(x)*length(y)), c(length(x), length(y))) image(x, 
y, z, useRaster=FALSE) # ok image(x, y, z, useRaster=TRUE) # error: 
'useRaster = TRUE' can only be used with a regular grid x <- y <- 
seq_len(12) image(x, y, z, useRaster=FALSE) # ok image(x, y, z, 
useRaster=TRUE) # ok The difference is the plot quality: useRaster = 
TRUE yields better quality as it omits strange white lines (in both 
png and pdf). I did not find a pattern when those white lines appear 
and when not. Hence, I cannot provide a reproducable example in which 
you can see the differences induced by the useRaster argument. In 
simple examples like the one above there is no difference between 
useRaster true and false plots. Do you have a suggestion on how to 
continue? Thanks a lot, Chris Am 14.04.2021 04:37 schrieb Paul Murrell:
Hi I doubt it is intended (to deliberately exclude "difftime" 
objects). Can you please supply a full image() example (with 'x' 
and/or 'y' as Dates and a 'z') ? So that I can see what ... image(x, 
y, z, useRaster=FALSE) ... looks like, so I can see what you want 
... image(x, y, z, useRaster=TRUE) ... to look like. I also wonder 
whether switching to ... dx[1][rep(1, length(dx))] ... might be 
better than switching to ... as.numeric(dx) It produces the same 
result for "difftime" objects, and may have a better chance of 
working better with other objects (although I confess that not 
having thought of using a "difftime" for 'x' I am also failing to 
think of further possibilities for 'x'). Paul On 14/04/21 3:11 
am,cda...@posteo.de  
> wrote:
Hi The function `check_irregular()` defined within 
`graphics::image.default()` checks if the `useRaster` argument for 
`graphics::image()` can be true or must be false. According to this 
function, the following example vector is irregular: ``` time <- 
seq(as.Date("2020-1-1"), as.Date("2020-12-31"), l=12) 
check_irregular(time, time) # TRUE ``` In my view, this is not 
correct. In this case, the `all.equal`-call does not evaluate to 
true due to the special class of `dx` (or `dy`). If I slightly 
rewrite the function as ``` my_check_irregular <- function (x, y) { 
dx <- as.numeric(diff(x)) dy <- as.numeric(diff(y)) (length(dx) && 
!isTRUE(all.equal(dx, rep(dx[1], length(dx) || (length(dy) && 
!isTRUE(all.equal(dy, rep(dy[1], length(dy) } ``` the correct 

Re: [R] Bug? Index output of C functions R_qsort_I and R_qsort_int_I is not modified

2021-04-15 Thread Bill Dunlap
R_ext/Utils.h:void R_qsort_int_I(int *iv, int *II, int i, int j);

The last 2 arguments are int, not int*.  .C() passes pointers to vectors so
you cannot call this function directly from .C().

-Bill

On Thu, Apr 15, 2021 at 3:15 PM Evangelos Evangelou via R-help <
r-help@r-project.org> wrote:

> Hi all.
>
> Reading the documentation of these two functions
>
> https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Utility-functions
> "The ..._I() versions also return the sort.index() vector in I."
> I can't find anything in the documentation about sort.index(), but I'm
> guessing that I is the index that makes the input sorted, as in R's
> order(). However running the following code on
> R version 4.0.5 (2021-03-31) Platform: x86_64-pc-linux-gnu (64-bit)
> does not give me that. It just gives me the original input.
>
> Rlib = file.path(Sys.getenv("R_HOME"), "lib", paste0("libR",
> .Platform$dynlib.ext))
> dyn.load(Rlib)
> n = 4L
> ix = n:1
> i = integer(n)
> cc = .C("R_qsort_int_I", ix, i, 1L, n)
> cc[[2]]
>
> I expect 4 3 2 1, but I get 0 0 0 0. Is this a bug or have I misunderstood
> something?
>
> Best,
> Vangelis
>
> [[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.


[ESS] Announcing ‘Introductions to Emacs Speaks Statistics'

2021-04-15 Thread Dirk Eddelbuettel via ESS-help


(This is a text-only, no-links copy of what I just put onto my blog at 
http://dirk.eddelbuettel.com/blog/2021/04/15#announcing_ess_intros
where you find it with links. The key site is https://ess-intro.github.io.)

Announcing ‘Introductions to Emacs Speaks Statistics’

A new website containing introductory videos and slide decks is now available
for your perusal at ess-intro.github.io. It provides a series of
introductions to the excellent Emacs Speaks Statistics (ESS) mode for the
Emacs editor.

This effort started following my little tips, tricks, tools and toys series
of short videos and slide decks “for the command-line and R,
broadly-speaking”. Which I had mentioned to friends curious about Emacs, and
on the ess-help mailing list. And lo and behold, over the fall and winter
sixteen of us came together in one GitHub org and are now proud to present
the initial batch of videos about first steps, installing, using with
spaceemacs, customizing, and org-mode with ESS. More may hopefully fellow,
the group is open and you too can join: see the main repo and its wiki.

This is in fact the initial announcement post, so it is flattering that we
have already received over 350 views, four comments and twenty-one likes.

We hope it proves to be a useful starting point for some of you. The Emacs
editor is quite uniquely powerful, and coupled with ESS makes for a rather
nice environment for programming with data, or analysing, visualising,
exploring, … data. But we are not zealots: there are many editors and
environments under the sun, and most people are perfectly happy with their
choice, which is wonderful. We also like ours, and sometimes someone asks
‘tell me more’ or ‘how do I start’. We hope this series satisifies this
initial curiousity and takes it from here.

With that, my thanks to Frédéric, Alex, Tyler and Greg for the initial batch,
and for everybody else in the org who chipped in with comments and
suggestion. We hope it grows from here, so happy Emacsing with R from us!


For the group,  Dirk


-- 
https://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] geom_node_point color in ggraph

2021-04-15 Thread Wolfgang Grond
Rui,

thanks a lot, I'll try it this way.

Best regards

Wolfgang

Am 15. April 2021 21:19:27 MESZ schrieb Rui Barradas :
>Hello,
>
>To define the colors, remove the data set name from the aesthetic.
>This
>
>aes(colour = project_all$Acronym)
>
>
>should be this
>
>aes(colour = Acronym)
>
>
>Then choose the colours in the usual ggplot way. Here is a reproducible
>
>example.
>
>
>library(igraph)
>library(ggraph)
>
>project_all <- make_graph("bull")
>vertex_attr(project_all, "Acronym", index = V(project_all)) <- "red"
>vertex_attr(project_all, "Acronym", index = V(project_all)[[3]]) <-
>"blue"
>
>ggraph(project_all, layout = "igraph", algorithm = "kk") +
>   geom_edge_link() +
>   geom_node_point(aes(colour = Acronym), size = 8) +
>   scale_color_manual(name = "Project / Projekt",
>  values = c("blue", "red"))
>
>
>Hope this helps,
>
>Rui Barradas
>
>
>Às 15:57 de 15/04/21, Wolfgang Grond escreveu:
>> Dear all,
>> 
>> I'm joining differnts graphs to one with command graph_join from
>ggraph,
>> 
>> and try to color the nodes depending on the subgraph they come from.
>> 
>> To do that, I have these commands in my ggraph:
>> 
>> 
>> 
>> ...
>> geom_node_point(size = 8, aes(colour = project_all$Acronym)) +
>>       scale_color_discrete(name="Project / Projekt") +
>> ...
>> 
>> 
>> 
>> All works well, but
>> 
>> how to define the colors to use for the nodes?
>> 
>> Is it possible to either
>> 
>> - define the colors explicitely, or
>> 
>> - define a color palette to use?
>> 
>> Please point me to where I should look how to do it.
>> 
>> Many thanks in advance
>> 
>> Wolfgang
>> 
>> 
>>  [[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.

[[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] Bug? Index output of C functions R_qsort_I and R_qsort_int_I is not modified

2021-04-15 Thread Evangelos Evangelou via R-help
Hi all.

Reading the documentation of these two functions
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Utility-functions
"The ..._I() versions also return the sort.index() vector in I."
I can't find anything in the documentation about sort.index(), but I'm guessing 
that I is the index that makes the input sorted, as in R's order(). However 
running the following code on
R version 4.0.5 (2021-03-31) Platform: x86_64-pc-linux-gnu (64-bit)
does not give me that. It just gives me the original input.

Rlib = file.path(Sys.getenv("R_HOME"), "lib", paste0("libR", 
.Platform$dynlib.ext))
dyn.load(Rlib)
n = 4L
ix = n:1
i = integer(n)
cc = .C("R_qsort_int_I", ix, i, 1L, n)
cc[[2]]

I expect 4 3 2 1, but I get 0 0 0 0. Is this a bug or have I misunderstood 
something?

Best,
Vangelis

[[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] graphics useRaster check_irregular definition for date or posix

2021-04-15 Thread cdanek
 Hi Paul

Thanks for the FAQs related to the unwanted white lines. However, even
if it is just the png/pdf viewer that causes the white lines, I would
like to try to avoid them as much as possible, and setting useRaster to
true does that.

My wish would be that I can use a date or POSIX* vector as x and/or y
axis as it is without using some numerical values instead and then
always need to take special care for the corresponding labels.
Particularly for date/POSIX* objects this can be annoying. So the axes
or their labels are not my problem, I just need the useRaster true or
false decision to be consistent.

How do you deduce that the diff of the midpoints (i.e. the modifided x)
is not "regular"? This, again, will be decided later in image.default()
by check_irregular(), what brings us back to my initial post?

Cheers,
Chris

Am 15.04.2021 03:26 schrieb Paul Murrell: 

> Hi
> 
> Feeding R-help back in, in case my suggestions might be of use to someone 
> else ...
> 
> Thanks for the examples - so the main benefit you are looking for is the 
> labelling on the axes (date labels) ?
> 
> If you are just trying to avoid the annoying white lines, it may just be your 
> PNG/PDF viewer; see ...
> 
> http://cran.stat.auckland.ac.nz/doc/FAQ/R-FAQ.html#Why-are-there-unwanted-borders
>  [1]
> 
> Even so, making this work for date values for x/y seems like a useful thing. 
> However, ...
> 
> Neither your "fix" nor my "fix" actually works for the example that you have 
> provided. It just reveals another problem within image.default(), which is 
> the calculation of "midpoints" ...
> 
> if (length(x) > 1 && length(x) == nrow(z)) { # midpoints
> dx <- 0.5*diff(x)
> x <- c(x[1L] - dx[1L], x[-length(x)] + dx,
> x[length(x)] + dx[length(x)-1])
> }
> 
> This calculation does NOT produce the desired result for "Date"s (the diff() 
> of the resulting modified 'x' is no longer regular).
> 
> So this needs a bit more thought - let me know if you come up with a fix for 
> that calculation before me :)
> 
> Paul
> 
> On 15/04/21 4:05 am, cda...@posteo.de wrote:
> Hi Paul Thanks for your answer. I just answer to you, I dont know if this is 
> correct (also the maillist?) x <- y <- seq(as.Date("2020-1-1"), 
> as.Date("2020-12-31"), l=12) z <- array(rnorm(length(x)*length(y)), 
> c(length(x), length(y))) image(x, y, z, useRaster=FALSE) # ok image(x, y, z, 
> useRaster=TRUE) # error: 'useRaster = TRUE' can only be used with a regular 
> grid x <- y <- seq_len(12) image(x, y, z, useRaster=FALSE) # ok image(x, y, 
> z, useRaster=TRUE) # ok The difference is the plot quality: useRaster = TRUE 
> yields better quality as it omits strange white lines (in both png and pdf). 
> I did not find a pattern when those white lines appear and when not. Hence, I 
> cannot provide a reproducable example in which you can see the differences 
> induced by the useRaster argument. In simple examples like the one above 
> there is no difference between useRaster true and false plots. Do you have a 
> suggestion on how to continue? Thanks a lot, Chris Am 14.04.2021 04:37 
> schrieb Paul Murrell: Hi I
doubt it is intended (to deliberately exclude "difftime" objects). Can you 
please supply a full image() example (with 'x' and/or 'y' as Dates and a 'z') ? 
So that I can see what ... image(x, y, z, useRaster=FALSE) ... looks like, so I 
can see what you want ... image(x, y, z, useRaster=TRUE) ... to look like. I 
also wonder whether switching to ... dx[1][rep(1, length(dx))] ... might be 
better than switching to ... as.numeric(dx) It produces the same result for 
"difftime" objects, and may have a better chance of working better with other 
objects (although I confess that not having thought of using a "difftime" for 
'x' I am also failing to think of further possibilities for 'x'). Paul On 
14/04/21 3:11 am,cda...@posteo.de  wrote: Hi The 
function `check_irregular()` defined within `graphics::image.default()` checks 
if the `useRaster` argument for `graphics::image()` can be true or must be 
false. According to this function, the following example vector is
irregular: ``` time <- seq(as.Date("2020-1-1"), as.Date("2020-12-31"), l=12) 
check_irregular(time, time) # TRUE ``` In my view, this is not correct. In this 
case, the `all.equal`-call does not evaluate to true due to the special class 
of `dx` (or `dy`). If I slightly rewrite the function as ``` my_check_irregular 
<- function (x, y) { dx <- as.numeric(diff(x)) dy <- as.numeric(diff(y)) 
(length(dx) && !isTRUE(all.equal(dx, rep(dx[1], length(dx) || (length(dy) 
&& !isTRUE(all.equal(dy, rep(dy[1], length(dy) } ``` the correct answer is 
obtained (i.e. that the input vector is not irregular based on the rational 
behind `all.equal`): ``` my_check_irregular(time, time) # FALSE ``` The same 
applies to POSIX* objects. I was wondering if this is intended or not? Thanks a 
lot for any answer, Chris [[alternative HTML version deleted]] 

[R] Is R supported on Virtual Infrastructure environment?

2021-04-15 Thread Felyn Tay
Good Morning!

I would like to find out whether there is any documentation or anyone has 
experience running R on Virtual Infrastructure Environment, particularly VMWare 
Horizon.

Thank you!

Felyn

[[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] geom_node_point color in ggraph

2021-04-15 Thread Rui Barradas

Hello,

To define the colors, remove the data set name from the aesthetic.
This

aes(colour = project_all$Acronym)


should be this

aes(colour = Acronym)


Then choose the colours in the usual ggplot way. Here is a reproducible 
example.



library(igraph)
library(ggraph)

project_all <- make_graph("bull")
vertex_attr(project_all, "Acronym", index = V(project_all)) <- "red"
vertex_attr(project_all, "Acronym", index = V(project_all)[[3]]) <- "blue"

ggraph(project_all, layout = "igraph", algorithm = "kk") +
  geom_edge_link() +
  geom_node_point(aes(colour = Acronym), size = 8) +
  scale_color_manual(name = "Project / Projekt",
 values = c("blue", "red"))


Hope this helps,

Rui Barradas


Às 15:57 de 15/04/21, Wolfgang Grond escreveu:

Dear all,

I'm joining differnts graphs to one with command graph_join from ggraph,

and try to color the nodes depending on the subgraph they come from.

To do that, I have these commands in my ggraph:



...
geom_node_point(size = 8, aes(colour = project_all$Acronym)) +
      scale_color_discrete(name="Project / Projekt") +
...



All works well, but

how to define the colors to use for the nodes?

Is it possible to either

- define the colors explicitely, or

- define a color palette to use?

Please point me to where I should look how to do it.

Many thanks in advance

Wolfgang


[[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] Weighted violin chart

2021-04-15 Thread Mahmood Naderan-Tahan
Correct. This one


p <- ggplot(mydata, aes(x=V3, y=V1, weight=V2)) + geom_violin(trim=FALSE)


works fine. Thank you very much.

Regards,
Mahmood


From: Duncan Murdoch 
Sent: Thursday, April 15, 2021 5:24:04 PM
To: Mahmood Naderan-Tahan; r-help@r-project.org
Subject: Re: [R] Weighted violin chart

On 15/04/2021 11:07 a.m., Mahmood Naderan-Tahan wrote:
> It seems that using weight in ggplot has no effect. Also, using weight 
> parameter in geom_violin results in an error.
>
>
>> mydata
>   V1 V2 V3
> P1 73.6  5  R
> P2 75.2  5  R
> P3  6.5 60  R
> P4 41.4 15  C
> P5  5.4  5  C
> P6 18.8 10  C
>> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
>> p
>> p <- ggplot(mydata, aes(x=V3, y=V1), weight=V2) + geom_violin(trim=FALSE)

That's not what Jeff suggested.  weight should be an argumnent to aes().

Duncan Murdoch

>> p
>
> In the code above, there is no difference between the two charts.
> Also, the following code ends up in an error
>
>> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE, 
>> weight=mydata$V2)
>> p
> Error: Aesthetics must be either length 1 or the same as the data (1024): 
> weight
> Run `rlang::last_error()` to see where the error occurred.
>> mydata$V2
> [1] 50 20  5 10 10  5
>
>
> Any idea to fix that?
>
>
> Regards,
> Mahmood
>
>
> 
>
>>> 
>>> From: Jeff Newmiller 
>>> Sent: Thursday, April 15, 2021 4:13:10 PM
>>> To: r-help@r-project.org; Mahmood Naderan-Tahan; r-help@r-project.org
>>> Subject: Re: [R] Weighted violin chart
>>>
>>> Not strictly on topic on this list (ggplot2 is a contributed package)
>>> but...
>>>
>>> ggplot(mydata, aes(x=V3, y=V1, weight=V2 )) + geom_violin(trim=FALSE)
>>>
>>> If you want to refer to variables in the data, they have to be listed
>>> in the mapping.
>>>
>>> On April 15, 2021 7:01:45 AM PDT, Mahmood Naderan-Tahan
>>>  wrote:
 Hi again,

 As a follow up, does anybody know how to fix the following error?

 It seems that I can use a "weight" parameter in geom_violin, but I am
 able to  figure out what is the problem with the following code.



> library(ggplot2)

> mydata <- read.csv('test.csv', header=T,row.names=1)
> mydata
  V1 V2 V3
 P1 73.6 50  R
 P2 75.2 20  R
 P3  6.5  5  R
 P4 41.4 10  C
 P5  5.4 10  C
 P6 18.8  5  C
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,
 weight=V2)
 Error in layer(data = data, mapping = mapping, stat = stat, geom =
 GeomViolin,  :
   object 'V2' not found
>
>
> wg <- as.factor(mydata$V2)
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,
 weight=wg)
> p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
 `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
 Error: Aesthetics must be either length 1 or the same as the data
 (1024): weight
 Run `rlang::last_error()` to see where the error occurred.





 Regards,
 Mahmood


 
 From: Mahmood Naderan-Tahan
 Sent: Monday, April 12, 2021 10:01 PM
 To: r-help@r-project.org
 Subject: Weighted violin chart


 Hi,

 I would like to know if it is possible to plot a weighted violin
>> chart
 with R. Currently, I have


> library(ggplot2)
> mydata <- read.csv('test.csv', header=T,row.names=1)
> mydata
  V1 V2 V3
 P1 73.6 50  R
 P2 75.2 20  R
 P3  6.5  5  R
 P4 41.4 10  C
 P5  5.4 10  C
 P6 18.8  5  C
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
> p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

 I would like to use V2 as the weight vector. Any idea about that?



 Regards,
 Mahmood

[[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.
>>
>> --
>> Sent from my phone. Please excuse my brevity.
>
> --
> 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.
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To 

Re: [R] Weighted violin chart

2021-04-15 Thread Duncan Murdoch

On 15/04/2021 11:07 a.m., Mahmood Naderan-Tahan wrote:

It seems that using weight in ggplot has no effect. Also, using weight 
parameter in geom_violin results in an error.



mydata

  V1 V2 V3
P1 73.6  5  R
P2 75.2  5  R
P3  6.5 60  R
P4 41.4 15  C
P5  5.4  5  C
P6 18.8 10  C

p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
p
p <- ggplot(mydata, aes(x=V3, y=V1), weight=V2) + geom_violin(trim=FALSE)


That's not what Jeff suggested.  weight should be an argumnent to aes().

Duncan Murdoch


p


In the code above, there is no difference between the two charts.
Also, the following code ends up in an error


p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE, weight=mydata$V2)
p

Error: Aesthetics must be either length 1 or the same as the data (1024): weight
Run `rlang::last_error()` to see where the error occurred.

mydata$V2

[1] 50 20  5 10 10  5


Any idea to fix that?


Regards,
Mahmood






From: Jeff Newmiller 
Sent: Thursday, April 15, 2021 4:13:10 PM
To: r-help@r-project.org; Mahmood Naderan-Tahan; r-help@r-project.org
Subject: Re: [R] Weighted violin chart

Not strictly on topic on this list (ggplot2 is a contributed package)
but...

ggplot(mydata, aes(x=V3, y=V1, weight=V2 )) + geom_violin(trim=FALSE)

If you want to refer to variables in the data, they have to be listed
in the mapping.

On April 15, 2021 7:01:45 AM PDT, Mahmood Naderan-Tahan
 wrote:

Hi again,

As a follow up, does anybody know how to fix the following error?

It seems that I can use a "weight" parameter in geom_violin, but I am
able to  figure out what is the problem with the following code.




library(ggplot2)



mydata <- read.csv('test.csv', header=T,row.names=1)
mydata

 V1 V2 V3
P1 73.6 50  R
P2 75.2 20  R
P3  6.5  5  R
P4 41.4 10  C
P5  5.4 10  C
P6 18.8  5  C

p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,

weight=V2)
Error in layer(data = data, mapping = mapping, stat = stat, geom =
GeomViolin,  :
  object 'V2' not found



wg <- as.factor(mydata$V2)
p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,

weight=wg)

p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
Error: Aesthetics must be either length 1 or the same as the data
(1024): weight
Run `rlang::last_error()` to see where the error occurred.





Regards,
Mahmood



From: Mahmood Naderan-Tahan
Sent: Monday, April 12, 2021 10:01 PM
To: r-help@r-project.org
Subject: Weighted violin chart


Hi,

I would like to know if it is possible to plot a weighted violin

chart

with R. Currently, I have



library(ggplot2)
mydata <- read.csv('test.csv', header=T,row.names=1)
mydata

 V1 V2 V3
P1 73.6 50  R
P2 75.2 20  R
P3  6.5  5  R
P4 41.4 10  C
P5  5.4 10  C
P6 18.8  5  C

p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)


I would like to use V2 as the weight vector. Any idea about that?



Regards,
Mahmood

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


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


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



__
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] Weighted violin chart

2021-04-15 Thread Mahmood Naderan-Tahan
It seems that using weight in ggplot has no effect. Also, using weight 
parameter in geom_violin results in an error.


> mydata
 V1 V2 V3
P1 73.6  5  R
P2 75.2  5  R
P3  6.5 60  R
P4 41.4 15  C
P5  5.4  5  C
P6 18.8 10  C
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
> p
> p <- ggplot(mydata, aes(x=V3, y=V1), weight=V2) + geom_violin(trim=FALSE)
> p

In the code above, there is no difference between the two charts.
Also, the following code ends up in an error

> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE, 
> weight=mydata$V2)
> p
Error: Aesthetics must be either length 1 or the same as the data (1024): weight
Run `rlang::last_error()` to see where the error occurred.
> mydata$V2
[1] 50 20  5 10 10  5


Any idea to fix that?


Regards,
Mahmood




>>
>>From: Jeff Newmiller 
>>Sent: Thursday, April 15, 2021 4:13:10 PM
>>To: r-help@r-project.org; Mahmood Naderan-Tahan; r-help@r-project.org
>>Subject: Re: [R] Weighted violin chart
>>
>>Not strictly on topic on this list (ggplot2 is a contributed package)
>>but...
>>
>>ggplot(mydata, aes(x=V3, y=V1, weight=V2 )) + geom_violin(trim=FALSE)
>>
>>If you want to refer to variables in the data, they have to be listed
>>in the mapping.
>>
>>On April 15, 2021 7:01:45 AM PDT, Mahmood Naderan-Tahan
>> wrote:
>>>Hi again,
>>>
>>>As a follow up, does anybody know how to fix the following error?
>>>
>>>It seems that I can use a "weight" parameter in geom_violin, but I am
>>>able to  figure out what is the problem with the following code.
>>>
>>>
>>>
 library(ggplot2)
>>>
 mydata <- read.csv('test.csv', header=T,row.names=1)
 mydata
>>> V1 V2 V3
>>>P1 73.6 50  R
>>>P2 75.2 20  R
>>>P3  6.5  5  R
>>>P4 41.4 10  C
>>>P5  5.4 10  C
>>>P6 18.8  5  C
 p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,
>>>weight=V2)
>>>Error in layer(data = data, mapping = mapping, stat = stat, geom =
>>>GeomViolin,  :
>>>  object 'V2' not found


 wg <- as.factor(mydata$V2)
 p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,
>>>weight=wg)
 p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
>>>`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
>>>Error: Aesthetics must be either length 1 or the same as the data
>>>(1024): weight
>>>Run `rlang::last_error()` to see where the error occurred.
>>>
>>>
>>>
>>>
>>>
>>>Regards,
>>>Mahmood
>>>
>>>
>>>
>>>From: Mahmood Naderan-Tahan
>>>Sent: Monday, April 12, 2021 10:01 PM
>>>To: r-help@r-project.org
>>>Subject: Weighted violin chart
>>>
>>>
>>>Hi,
>>>
>>>I would like to know if it is possible to plot a weighted violin
>chart
>>>with R. Currently, I have
>>>
>>>
 library(ggplot2)
 mydata <- read.csv('test.csv', header=T,row.names=1)
 mydata
>>> V1 V2 V3
>>>P1 73.6 50  R
>>>P2 75.2 20  R
>>>P3  6.5  5  R
>>>P4 41.4 10  C
>>>P5  5.4 10  C
>>>P6 18.8  5  C
 p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
 p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
>>>
>>>I would like to use V2 as the weight vector. Any idea about that?
>>>
>>>
>>>
>>>Regards,
>>>Mahmood
>>>
>>>   [[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.
>
>--
>Sent from my phone. Please excuse my brevity.

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


[R] geom_node_point color in ggraph

2021-04-15 Thread Wolfgang Grond
Dear all,

I'm joining differnts graphs to one with command graph_join from ggraph,

and try to color the nodes depending on the subgraph they come from.

To do that, I have these commands in my ggraph:



...
geom_node_point(size = 8, aes(colour = project_all$Acronym)) +
     scale_color_discrete(name="Project / Projekt") +
...



All works well, but

how to define the colors to use for the nodes?

Is it possible to either

- define the colors explicitely, or

- define a color palette to use?

Please point me to where I should look how to do it.

Many thanks in advance

Wolfgang


[[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] Weighted violin chart

2021-04-15 Thread Jeff Newmiller
Not strictly on topic on this list (ggplot2 is a contributed package) but...

ggplot(mydata, aes(x=V3, y=V1, weight=V2 )) + geom_violin(trim=FALSE)

If you want to refer to variables in the data, they have to be listed in the 
mapping.

On April 15, 2021 7:01:45 AM PDT, Mahmood Naderan-Tahan 
 wrote:
>Hi again,
>
>As a follow up, does anybody know how to fix the following error?
>
>It seems that I can use a "weight" parameter in geom_violin, but I am
>able to  figure out what is the problem with the following code.
>
>
>
>> library(ggplot2)
>
>> mydata <- read.csv('test.csv', header=T,row.names=1)
>> mydata
> V1 V2 V3
>P1 73.6 50  R
>P2 75.2 20  R
>P3  6.5  5  R
>P4 41.4 10  C
>P5  5.4 10  C
>P6 18.8  5  C
>> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,
>weight=V2)
>Error in layer(data = data, mapping = mapping, stat = stat, geom =
>GeomViolin,  :
>  object 'V2' not found
>>
>>
>> wg <- as.factor(mydata$V2)
>> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE,
>weight=wg)
>> p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
>`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
>Error: Aesthetics must be either length 1 or the same as the data
>(1024): weight
>Run `rlang::last_error()` to see where the error occurred.
>
>
>
>
>
>Regards,
>Mahmood
>
>
>
>From: Mahmood Naderan-Tahan
>Sent: Monday, April 12, 2021 10:01 PM
>To: r-help@r-project.org
>Subject: Weighted violin chart
>
>
>Hi,
>
>I would like to know if it is possible to plot a weighted violin chart
>with R. Currently, I have
>
>
>> library(ggplot2)
>> mydata <- read.csv('test.csv', header=T,row.names=1)
>> mydata
> V1 V2 V3
>P1 73.6 50  R
>P2 75.2 20  R
>P3  6.5  5  R
>P4 41.4 10  C
>P5  5.4 10  C
>P6 18.8  5  C
>> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
>> p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
>
>I would like to use V2 as the weight vector. Any idea about that?
>
>
>
>Regards,
>Mahmood
>
>   [[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] Weighted violin chart

2021-04-15 Thread Mahmood Naderan-Tahan
Hi again,

As a follow up, does anybody know how to fix the following error?

It seems that I can use a "weight" parameter in geom_violin, but I am able to  
figure out what is the problem with the following code.



> library(ggplot2)

> mydata <- read.csv('test.csv', header=T,row.names=1)
> mydata
 V1 V2 V3
P1 73.6 50  R
P2 75.2 20  R
P3  6.5  5  R
P4 41.4 10  C
P5  5.4 10  C
P6 18.8  5  C
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE, weight=V2)
Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomViolin,  
:
  object 'V2' not found
>
>
> wg <- as.factor(mydata$V2)
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE, weight=wg)
> p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
Error: Aesthetics must be either length 1 or the same as the data (1024): weight
Run `rlang::last_error()` to see where the error occurred.





Regards,
Mahmood



From: Mahmood Naderan-Tahan
Sent: Monday, April 12, 2021 10:01 PM
To: r-help@r-project.org
Subject: Weighted violin chart


Hi,

I would like to know if it is possible to plot a weighted violin chart with R. 
Currently, I have


> library(ggplot2)
> mydata <- read.csv('test.csv', header=T,row.names=1)
> mydata
 V1 V2 V3
P1 73.6 50  R
P2 75.2 20  R
P3  6.5  5  R
P4 41.4 10  C
P5  5.4 10  C
P6 18.8  5  C
> p <- ggplot(mydata, aes(x=V3, y=V1)) + geom_violin(trim=FALSE)
> p + geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

I would like to use V2 as the weight vector. Any idea about that?



Regards,
Mahmood

[[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] mgcv::gam() scale parameter estimates for quasibinomial error models

2021-04-15 Thread Simon Wood
Thanks John. It's a bug in weights handling. mgcv will give wrong scale 
parameter estimates for weighted models where the scale parameter is 
unknown, (except Gaussian, fortunately). quasibinomial with trials > 1 
is one such case, because the weights are used to store the number of 
trials. Otherwise the problem would only arise if weights were 
explicitly provided in a non-Gaussian model with unknown scale 
parameter. Fixed for 1. 8-35. best,


Simon

On 15/04/2021 06:39, John Maindonald wrote:

For both glm() and mgcv::gam() quasibinomial error models, the summary
object has a dispersion value that has the same role as sigma^2 in the
summary object for lm() model fits.

Where some fitted probabilities are small, the `gam()` default scale parameter
estimates, returned as `scale` (and `sig2`) in the gam object and as 
“dispersion"
in the summary object, can differ wildly from the Pearson values that `glm()`
works with, and that can be obtained by calling `gam()` with a suitable control
setting (see the code that now follows.)

The following demonstrates the issue:

   ## ‘mgcv’ version 1.8-34
   Cholera <- HistData:: Cholera
   library(mgcv)
   form <- cbind(cholera_deaths, popn-cholera_deaths) ~
  water + elevation + poor_rate
   default.gam <- gam(form, data=Cholera, family=quasibinomial)
   pearson.gam <- update(quasibin.gam, control=gam.control(scale.est=“pearson"))

   c(Pearson=pearson.gam$scale, Default=default.gam$scale)
   ##  Pearson Default
   ## 33.545829  2.919535

My own calculation (from either fitted model), returns 30.07 for the
(Fletcher 2012) version of the dispersion that was, according to
Wood’s “Generalized Additive Models” (2nd edn, 2017, p.111),
returned as the GAM scale estimate at the time when the book was
written.

The default scale estimates returned by `gam()` vary wildly, relative
to the relatively stable “pearson" estimates, in data that are simulated
to have comparable dispersion estimates.

For the Cholera data, it would make good sense to fit a model
with quasipoisson errors to the death counts, using log(popn) as an
offset.  The GAM model then uses, with default setting for `scale.est`,
a scale parameter that is close to that returned by "pearson.gam”.
SEs (as well as coefficients) are similar to those returned by
"pearson.gam”.

The detailed calculations that are documented in the following
documents may be of some general interest.
   https://www.dropbox.com/s/vl9usat07urbgel/quasibin-gam.pdf?dl=0
   or https://www.dropbox.com/s/s83mh1mut5xc3gk/quasibin-gam.html?dl=0

I am posting this here now before posting a bug report in case I have
missed something important.  It would be useful to be directed to the
mgcv code used for calculation of what is returned as the Fletcher statistic.

   Rmd file: https://www.dropbox.com/s/ghmsdcvgxp068bs/quasibin-gam.Rmd?dl=0
   .bib file: https://www.dropbox.com/s/r1yjqx0sni2pzjy/quasi.bib?dl=0

John Maindonald email: john.maindon...@anu.edu.au


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


--
Simon Wood, School of Mathematics, University of Edinburgh,
https://www.maths.ed.ac.uk/~swood34/

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