SCM

SCM Repository

[directlabels] Diff of /tex/2012-semin-r/2012-03-29-HOCKING-directlabels-semin-r.Rnw
ViewVC logotype

Diff of /tex/2012-semin-r/2012-03-29-HOCKING-directlabels-semin-r.Rnw

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 583, Tue Mar 27 22:12:46 2012 UTC revision 584, Tue Mar 27 22:28:31 2012 UTC
# Line 18  Line 18 
18    
19  <<echo=FALSE,results='hide',cache=FALSE>>=  <<echo=FALSE,results='hide',cache=FALSE>>=
20  options(width=60)  options(width=60)
21    if(!require(EBImage)){
22      source("http://bioconductor.org/biocLite.R")
23      biocLite("EBImage")
24      library(EBImage)
25    }
26  library(grid)  library(grid)
27  big.last <- list(cex=1.5,"last.qp")  big.last <- list(cex=1.5,"last.qp")
28  library(directlabels)  library(directlabels)
# Line 25  Line 30 
30  library(ggplot2)  library(ggplot2)
31  library(proto)  library(proto)
32  library(quadprog)  library(quadprog)
33    data(prostate,package="ElemStatLearn")
34    pros <- subset(prostate,select=-train,train==TRUE)
35    ycol <- which(names(pros)=="lpsa")
36    x <- as.matrix(pros[-ycol])
37    y <- pros[[ycol]]
38    library(lars)
39    fit <- lars(x,y,type="lasso")
40    beta <- scale(coef(fit),FALSE,1/fit$normx)
41    arclength <- rowSums(abs(beta))
42    library(reshape2)
43    path <- data.frame(melt(beta),arclength)
44    names(path)[1:3] <- c("step","variable","standardized.coef")
45    
46  @  @
47    
48    
# Line 105  Line 123 
123    
124    
125    
126    \begin{frame}
127      \frametitle{lasso plot}
128    <<>>=
129    lasso.plot <- ggplot(path,aes(arclength,standardized.coef,colour=variable))+
130      geom_line(aes(group=variable))+
131      opts(title="LASSO path for prostate cancer data calculated using the LARS")+
132      xlim(0,20)
133    direct.label(lasso.plot)
134    
135    @
136    \end{frame}
137    
138    \begin{frame}
139      \frametitle{lasso plot better}
140    <<>>=
141    lasso.plot <- ggplot(path,aes(arclength,standardized.coef,colour=variable))+
142      geom_line(aes(group=variable))+
143      opts(title="LASSO path for prostate cancer data calculated using the LARS")+
144      xlim(0,20)
145    direct.label(lasso.plot,lasso.labels)
146    
147    @
148    \end{frame}
149    
150  % http://directlabels.r-forge.r-project.org/docs/scatterplot/plots/iris.html  % http://directlabels.r-forge.r-project.org/docs/scatterplot/plots/iris.html
151    
# Line 139  Line 179 
179  \end{frame}  \end{frame}
180    
181    
 \begin{frame}[fragile]  
   \frametitle{Label a scatterplot of the iris data by species}  
 <<dev='png'>>=  
 set.seed(1)  
 library(ggplot2)  
 p <- ggplot(iris,aes(jitter(Sepal.Length),jitter(Petal.Length)))+  
   geom_point(aes(colour=Species))  
 source("iris-images.R")  
 pimg <- p+  
   GeomImageLabel$new(aes(label=Species),  
                       method=find.empty.box,  
                       images=iris.photos)  
 library(directlabels)  
 direct.label(pimg)  
 @  
 \end{frame}  
   
   
   
   
 \begin{frame}[fragile]  
   \frametitle{Construct your own custom Positioning Method}  
 <<>>=  
 rp2 <- ratplot+  
   xlim(0,70)+ylim(150,650)  
 big.last <- list(cex=1.5,"last.qp")  
 direct.label(rp2,"big.last")  
 @  
 \end{frame}  
   
 \begin{frame}[fragile]  
   \frametitle{Construct your own custom Positioning Method}  
 <<>>=  
 direct.label(rp2,  
   list("big.last",  
        "calc.boxes",  
        "draw.rects"))#p  
 @  
 \end{frame}  
   
 \begin{frame}[fragile]  
   \frametitle{Construct your own custom Positioning Method}  
 <<>>=  
 spaced.last <- list(last.points,cex=1.5,calc.boxes,  
                     dl.trans(h=h+h/3),calc.borders,  
                     draw.rects,qp.labels("y","h"))  
 direct.label(rp2,spaced.last)  
 @  
 \end{frame}  
182    
183    
184    
# Line 232  Line 223 
223     \end{tabular}     \end{tabular}
224  \end{frame}  \end{frame}
225    
226    
227    \begin{frame}[fragile]
228      \frametitle{Label a scatterplot of the iris data by species}
229    <<>>=
230    direct.label(irisp,debug=TRUE)
231    @
232    \end{frame}
233    
234    
235    
236    
237    
238    
239    \begin{frame}[fragile]
240      \frametitle{Construct your own custom Positioning Method}
241    <<>>=
242    rp2 <- ratplot+
243      xlim(0,70)+ylim(150,650)
244    big.last <- list(cex=1.5,"last.qp")
245    direct.label(rp2,"big.last")
246    @
247    \end{frame}
248    
249    \begin{frame}[fragile]
250      \frametitle{Construct your own custom Positioning Method}
251    <<>>=
252    direct.label(rp2,
253      list("big.last",
254           "calc.boxes",
255           "draw.rects"))#p
256    @
257    \end{frame}
258    
259    \begin{frame}[fragile]
260      \frametitle{Construct your own custom Positioning Method}
261    <<>>=
262    spaced.last <- list(last.points,cex=1.5,calc.boxes,
263                        dl.trans(h=h+h/3),calc.borders,
264                        draw.rects,qp.labels("y","h"))
265    direct.label(rp2,spaced.last)
266    @
267    \end{frame}
268    
269    
270    
271    
272  % - lineplot QP  % - lineplot QP
273    
274  % - scatterplot grid search  % - scatterplot grid search
# Line 267  Line 304 
304  @  @
305  \end{frame}  \end{frame}
306    
307  \begin{frame}  \begin{frame}[fragile]
308    \frametitle{Use directlabels instead of confusing legends!}    \frametitle{Use directlabels instead of confusing legends!}
309    
310    \begin{itemize}    \begin{itemize}
# Line 285  Line 322 
322      \item Label using images instead of textual factor names?\\      \item Label using images instead of textual factor names?\\
323        Possible Google Summer of Code 2012 project:\\        Possible Google Summer of Code 2012 project:\\
324        {\scriptsize \url{http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2012}}        {\scriptsize \url{http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2012}}
325    
326      \end{itemize}      \end{itemize}
327    \end{itemize}    \end{itemize}
328    <<echo=FALSE,results='hide',dev='png',fig.height=10,fig.width=10,out.width='2in'>>=
329    set.seed(1)
330    library(ggplot2)
331    p <- ggplot(iris,aes(jitter(Sepal.Length),jitter(Petal.Length)))+
332      geom_point(aes(colour=Species))
333    source("iris-images.R")
334    pimg <- p+
335      GeomImageLabel$new(aes(label=Species),
336                          method=find.empty.box,
337                          images=iris.photos)
338    library(directlabels)
339    direct.label(pimg)
340    @
341  \end{frame}  \end{frame}
342    
343  \end{document}  \end{document}

Legend:
Removed from v.583  
changed lines
  Added in v.584

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge