Study Note for R ggplot学习100例
GGplot实操100练
GGplot实操100练
#并行计算-parallel包 #parallel包的思路和lapply函数很相似,都是将输入数据分割、计算、整合结果。只不过并行计算是用到了不同的cpu来运算。下面的例子是解决欧拉问题的第14个问题。 # 并行计算euler14问题 # 自定义函数以返回原始数值和步数 library(parallel) func <- function(x) { n = 1 raw <- x while (x > 1) { x <- ifelse(x%%2==0,x/2,3*x+1) n = n + 1 } return(c(raw,n)) } library(parallel) # 用system.time来返回计算所需时间 system.time({ x <- 1:1e6 cl <- makeCluster(4) # 初始化四核心集群 results <- parLapply(cl,x,func) # lapply的并行版本 res.df <- do.call('rbind',results) # 整合结果 stopCluster(cl) [...]
#Multiplot in ggplot2 install.packages("gridExtra") library("gridExtra") install.packages("cowplot") library("cowplot") df <- ToothGrowth # Convert the variable dose from a numeric to a factor variable df$dose <- as.factor(df$dose) head(df) #----Cowplot---- # The cowplot package is an extension to ggplot2 #and it can be used to provide a publication-ready plots. library(cowplot) # Default plot bp <- ggplot(df, aes(x=dose, y=len, color=dose)) [...]
Here is an interesting package called 'profvis' that I recently get to know about. It is quite useful when you are trying to locate the place where takes the longest time when running the code. Below is an official example. #R system monitoring install.packages('profvis') library(profvis) # To run code with profiling, wrap the expression in profvis(). [...]
Date: 2017/04/16 source: http://math.usu.edu/jrstevens/stat5570/2.3.Clustering.pdf # Heatmap Trial library(cluster) library(RColorBrewer) set.seed(123) x1 <- c(rnorm(20,sd=.05), rnorm(20,mean=1,sd=.05), rnorm(20,mean=1.5,sd=.05)) x2 <- 4+c(rnorm(20,sd=2), rnorm(20,mean=8,sd=1.5), rnorm(20,mean=8,sd=1)) x1.sc <- x1/sd(x1) x2.sc <- x2/sd(x2) hmcol <- colorRampPalette(brewer.pal(10,"RdBu"))(256) csc <- c(hmcol[50],hmcol[200]) # define side colors heatmap(cbind(x1.sc,x2.sc),scale="column",col=hmcol, ColSideColors=csc,cexCol=1.5,cexRow=.5) # ---- try with ALL datasets source("http://bioconductor.org/biocLite.R") biocLite(c('affy', 'ALL')) # download packages library(affy); library(ALL); data(ALL) gn <- featureNames(ALL) [...]
I believe most of you are quite familiar using R markdown to write either your analysis report or work sample, some of which requires a lot of formula and table writing. So here is what I find to be useful to do these jobs. Write math matrix \mathbf{X} = \left[\begin{array} {rrr} 1 & 2 & 3 [...]
Just finished an amazing tutorial textbook in 3 consecutive days. is such a fantastic book for both beginners and mid-level learners like me to review all the aspects of Data Science using R systematically and grab a more thorough understanding of data tidying methods, how to treat different data format effectively and utilize dplyr, lubridate and [...]
临近毕业,同学们最关心的事情,除了毕业照如何把自己拍的美美哒,就是自己的小伙伴们都去哪儿了。那么我们生科院2017届225名小伙伴们,你们都去哪儿了呢?