ggplot2 - R y axis normal -
i trying scale y-axis of plot normal distribution. example, plot.
the output of code gives me plot.
an equivalent "scale_y_normal" not exist, wondering if has ideas this? present code completeness, purely ggplot2 question please focus on last few lines of code. thanks!
library(foreign) # load foreign package (converts data files r) library(survey) # load survey package (analyzes complex design surveys) library(ggplot2) #-----------------------------------download , importation function download.nhanes.file <- function( ftp.filepath ){ # create temporary file downloading file local drive tf <- tempfile() # download file using ftp.filepath specified download.file( # download file stored in location designated above ftp.filepath , # save file temporary file assigned above tf , # download binary file type mode = "wb" ) # variable 'tf' contains full file path # on local computer specified file read.xport( tf ) # last line of function contains *returns* # putting read.xport final line, # function return r data frame } #-----------------------------------download files , creata data.frame x1112 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/2011-2012/glu_g.xpt") x0910 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/2009-2010/glu_f.xpt") x0708 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/2007-2008/glu_e.xpt") x0506 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/2005-2006/glu_d.xpt") x0304 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/2003-2004/l10am_c.xpt") x0102 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/2001-2002/l10am_b.xpt") x9900 <- download.nhanes.file("ftp://ftp.cdc.gov/pub/health_statistics/nchs/nhanes/1999-2000/lab10am.xpt") #rename 'lbdglusi' (only 99-02) colnames(x0102)[5] <- 'lbdglusi' colnames(x9900)[5] <- 'lbdglusi' #add column year x1112[,3] <- '11-12' x0910[,3] <- '09-10' x0708[,3] <- '07-08' x0506[,3] <- '05-06' x0304[,3] <- '03-04' x0102[,3] <- '01-02' x9900[,3] <- '99-00' #name varaible year colnames(x1112)[3] <- 'year' colnames(x0910)[3] <- 'year' colnames(x0708)[3] <- 'year' colnames(x0506)[3] <- 'year' colnames(x0304)[3] <- 'year' colnames(x0102)[3] <- 'year' colnames(x9900)[3] <- 'year' #stack data.frames on top of each other final <- rbind(x1112[,c("lbdglusi", "year")], x0910[,c("lbdglusi", "year")], x0708[,c("lbdglusi", "year")], x0506[,c("lbdglusi", "year")], x0304[,c("lbdglusi", "year")], x0102[,c("lbdglusi", "year")], x9900[,c("lbdglusi", "year")]) #-----------------------------------plot cumulative fasting blood glucose year ggplot(final, aes(x=final$lbdglusi, color=year)) + geom_point(aes(y=..y..),stat="ecdf") + xlab(expression(paste('serum glucose mm'))) + ylab('fraction of population') + ggtitle('nhanes fasting blood glucose') + coord_trans(x = 'log10')
Comments
Post a Comment