Weighted violin chart

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Weighted violin chart

Mahmood Naderan-Tahan
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Weighted violin chart

Chris Evans


----- Original Message -----
> From: "Mahmood Naderan-Tahan" <[hidden email]>
> To: [hidden email]
> Sent: Monday, 12 April, 2021 21:01:18
> Subject: [R] 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

There are, of course, nice ways to do this using base R but I am trying to convert to using tidyverse.
Here is one:

### use tribble to create a tibble rowwise
tribble(
  ~V1, ~V2, ~V3,
  73.6, 50, "R",
  75.2, 20, "R",
  6.5, 5, "R",
  41.4, 10, "C",
  5.4, 10, "C",
  18.8, 5, "C") -> myData

### use tidyr::uncount() to get to the data you want
myData %>%
  uncount(V2) -> tibWtdMyData

### plot it
ggplot(tibWtdMyData,
       aes(x=V3, y=V1)) +
  geom_violin(trim=FALSE) +
  geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

Of course, with so many identical values, I'm not sure a violin plot makes sense but perhaps you
were showing us a small subset of your data.

I have a nasty feeling there is a way of weighting things within ggplot.  If so, I am sure someone
will tell us.

For future, it's much easier for us to reply if you put small bits of data like your myData into
your Email using dput.  The output from dput doesn't look terribly human friendly but unless it
is mangled by HTML Emailing, it is wonderfully human friendly to use!

Very best (all),

Chris


--
Chris Evans (he/him) <[hidden email]> Visiting Professor, University of Sheffield <[hidden email]>
I do some consultation work for the University of Roehampton <[hidden email]> and other places
but <[hidden email]> remains my main Email address.  I have a work web site at:
   https://www.psyctc.org/psyctc/
and a site I manage for CORE and CORE system trust at:
   http://www.coresystemtrust.org.uk/
I have "semigrated" to France, see:
   https://www.psyctc.org/pelerinage2016/semigrating-to-france/ 
   https://www.psyctc.org/pelerinage2016/register-to-get-updates-from-pelerinage2016/

If you want an Emeeting, I am trying to keep them to Thursdays and my diary is at:
   https://www.psyctc.org/pelerinage2016/ceworkdiary/
Beware: French time, generally an hour ahead of UK.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Weighted violin chart

Mahmood Naderan-Tahan
In reply to this post by 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: [hidden email]
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Weighted violin chart

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 <[hidden email]> 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: [hidden email]
>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]]
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Weighted violin chart

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 <[hidden email]>
>>Sent: Thursday, April 15, 2021 4:13:10 PM
>>To: [hidden email]; Mahmood Naderan-Tahan; [hidden email]
>>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
>><[hidden email]> 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: [hidden email]
>>>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]]
>>>
>>>______________________________________________
>>>[hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Weighted violin chart

Duncan Murdoch-2
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 <[hidden email]>
>>> Sent: Thursday, April 15, 2021 4:13:10 PM
>>> To: [hidden email]; Mahmood Naderan-Tahan; [hidden email]
>>> 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
>>> <[hidden email]> 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: [hidden email]
>>>> 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]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Weighted violin chart

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 <[hidden email]>
Sent: Thursday, April 15, 2021 5:24:04 PM
To: Mahmood Naderan-Tahan; [hidden email]
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 <[hidden email]>
>>> Sent: Thursday, April 15, 2021 4:13:10 PM
>>> To: [hidden email]; Mahmood Naderan-Tahan; [hidden email]
>>> 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
>>> <[hidden email]> 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: [hidden email]
>>>> 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]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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]]
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.