Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-22 Thread Jim Lemon
Hi Ana, I think this is what you want in the panel style of plot. Let me know if not, or if I have calculated the wrong percentages. The overlaid histograms definitely use a different calculation. amsdf<-read.table("pheno_m1_plot",header=TRUE,stringsAsFactors=FALSE) dim(amsdf) # find the right

Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-22 Thread Ana Marija
Hi Eric, Thank you for getting back to me, I tried those solutions but they don't do percentage per groups, so if I do ggplot(data=subset(a, !is.na(pheno)), aes(x=HBA1C, fill=pheno)) + geom_histogram(aes(y = stat(density)), binwidth = 0.5) + scale_y_continuous(labels =

Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-22 Thread Ana Marija
HI Jim, Thank you so much for getting back to me I tried your codes and I got this in attach, I think the issue is in calculating percentage per groups (cases or controls) par(mfrow=c(2,1)) casehist<-table(cut(a$HBA1C[a$pheno=="case"],breaks=0:15))

Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-21 Thread Eric Berger
Hi Ana, This is a very common question about ggplot. A quick search turns up lots of hits that answer your question. Here are a couple https://community.rstudio.com/t/trouble-scaling-y-axis-to-percentages-from-counts/42999

Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-21 Thread Jim Lemon
Hi Ana, Just noticed a typo from a hasty cut-paste. Two lines should read: casehist<-table(cut(aafd$HBAIC[aafd$pheno=="case"],breaks=0:15)) controlhist<-table(cut(aafd$HBAIC[aafd$pheno=="control"],breaks=0:15)) Jim On Fri, May 22, 2020 at 2:08 PM Jim Lemon wrote: > > Hi Ana, > My apologies for

Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-21 Thread Jim Lemon
Hi Ana, My apologies for the pedestrian graphics, but it may help. # a bit of fake data aafd<-data.frame(FID=paste0("fam",1000:2739), IID=paste0("G",1000,2739),FLASER=rep(1,1740), PLASER=c(rep(1,892),rep(2,848)), DIABDUR=sample(10:50,1740,TRUE),

Re: [R] how to show percentage of individuals for two groups on histogram?

2020-05-21 Thread Ana Marija
the result would basically look something like this on in attach or the overlay of those two plots On Thu, May 21, 2020 at 5:23 PM Ana Marija wrote: > > Hello, > > I have a data frame like this: > > head(a) > FID IID FLASER PLASER DIABDUR HBA1C ESRD pheno > 1 fam1000-03 G1000

[R] how to show percentage of individuals for two groups on histogram?

2020-05-21 Thread Ana Marija
Hello, I have a data frame like this: > head(a) FID IID FLASER PLASER DIABDUR HBA1C ESRD pheno 1 fam1000-03 G1000 1 1 38 10.21 control 2 fam1001-03 G1001 1 1 15 7.31 control 3 fam1003-03 G1003 1 2 17 7.01case 4