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 <mahmood.nade...@ugent.be> 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.