Hi again,
Sorry, forgot this line:

 fpdf$PASPpos<-fpdf$PASP > 0

just after reading in the data frame.

Jim


On Thu, Jul 19, 2018 at 9:04 AM, Jim Lemon <drjimle...@gmail.com> wrote:
> Hi Francesca,
> This looks like a fairly simple task. Try this:
>
> fpdf<-read.table(text="PASP   SUBJC
>  0          0
>  4          1
>  0          0
>  8          0
>  4          0
>  0          1
>  0          1",
>  header=TRUE)
> # get the number of positive PASP results by group
> ppos<-by(fpdf$SUBJC,fpdf$PASPpos,sum)
> # get the number of subjects per group
> spg<-c(sum(fpdf$SUBJC==0),sum(fpdf$SUBJC==1))
> barplot(ppos/spg,names.arg=c(0,1),xlab="Group",
>  ylab="Proportion PASP > 0",main="Proportion of PASP positive by group")
>
> Jim
>
> On Thu, Jul 19, 2018 at 2:47 AM, Francesca <francesca.panco...@gmail.com> 
> wrote:
>> Dear R help,
>>
>> I am new to ggplot so I apologize if my question is a bit obvious.
>>
>> I would like to create a plot where a compare the fraction of the values of 
>> a variable called PASP out of the number of subjects, for two groups of 
>> subject codified with a dummy variable called SUBJC.
>>
>> The variable PASP is discrete and only takes values 0,4,8..
>>
>> My data are as following:
>>
>>
>>
>> PASP   SUBJC
>>
>>
>>
>> 0          0
>>
>> 4          1
>>
>> 0          0
>>
>> 8          0
>>
>> 4          0
>>
>> 0          1
>>
>> 0          1
>>
>> .           .
>>
>> .           .
>>
>> .           .
>>
>>
>>
>>
>> I would like to calculate the fraction of positive levels of PASP out of the 
>> total number of observations, divided per values of SUBJ=0 and 1. I am new 
>> to the use of GGPlot and I do not know how to organize the data and what to 
>> use to summarize these data as to obtain a picture as follows:
>>
>>
>>
>>
>>
>> I hope my request is clear. Thanks for any help you can provide.
>>
>> Francesca
>>
>>
>>
>> ______________________________________________
>> 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.

Reply via email to