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 582, Tue Mar 13 17:13:16 2012 UTC revision 583, Tue Mar 27 22:12:46 2012 UTC
# Line 19  Line 19 
19  <<echo=FALSE,results='hide',cache=FALSE>>=  <<echo=FALSE,results='hide',cache=FALSE>>=
20  options(width=60)  options(width=60)
21  library(grid)  library(grid)
22    big.last <- list(cex=1.5,"last.qp")
23  library(directlabels)  library(directlabels)
24  library(lattice)  library(lattice)
25  library(ggplot2)  library(ggplot2)
# Line 67  Line 68 
68    \begin{enumerate}    \begin{enumerate}
69    \item Make a lattice or ggplot2 plot \texttt{p} using colors and    \item Make a lattice or ggplot2 plot \texttt{p} using colors and
70      default legends.      default legends.
71    \item Try the default: \texttt{direct.label(p)}.    \item Try the default direct labels: \texttt{direct.label(p)}.
72    \item Check to see if another Positioning Method    \item Check to see if another Positioning Method
73      exists on\\{\small \url{http://directlabels.r-forge.r-project.org/docs/index.html}}      exists on\\{\small \url{http://directlabels.r-forge.r-project.org/docs/index.html}}
74      then use \texttt{direct.label(p,"method")}.      then use \texttt{direct.label(p,"method")}.
# Line 79  Line 80 
80  % http://directlabels.r-forge.r-project.org/docs/lineplot/plots/sexdeaths.html  % http://directlabels.r-forge.r-project.org/docs/lineplot/plots/sexdeaths.html
81    
82  \begin{frame}[fragile]  \begin{frame}[fragile]
83    \frametitle{Add default direct labels}    \frametitle{Add default direct labels at the mode of each density}
84  <<>>=  <<>>=
85  library(directlabels)  library(directlabels)
86  direct.label(dens)  direct.label(dens)
87  @  @
88  \end{frame}  \end{frame}
89    
90    \begin{frame}[fragile]
91      \frametitle{With 2 groups, we label the min and max points}
92    <<echo=FALSE,results='hide'>>=
93    tx <- time(mdeaths)
94    Time <- ISOdate(floor(tx),round(tx%%1 * 12)+1,1,0,0,0)
95    sexdf <- function(sex,x)data.frame(Time,sex,deaths=as.integer(x))
96    uk.lung <- rbind(sexdf("male",mdeaths),sexdf("female",fdeaths))
97    @
98    
99    <<>>=
100    p <- xyplot(deaths~Time,uk.lung,
101                groups=sex,type=c("l","g"))
102    direct.label(p)
103    @
104    \end{frame}
105    
106    
107    
108    
109    
110  % http://directlabels.r-forge.r-project.org/docs/scatterplot/plots/iris.html  % http://directlabels.r-forge.r-project.org/docs/scatterplot/plots/iris.html
111    
112  % 2---- examples: lineplot, scatterplot  % 2---- examples: lineplot, scatterplot
# Line 100  Line 121 
121  \end{frame}  \end{frame}
122    
123  \begin{frame}[fragile]  \begin{frame}[fragile]
124    \frametitle{The Positioning Method controls direct label placement}    \frametitle{Look up the Positioning Method on the directlabels website}
125  <<>>=  <<>>=
126  direct.label(ratplot,"last.qp")  direct.label(ratplot,"last.qp")
127  @  @
128  \end{frame}  \end{frame}
129    
130    
131  \begin{frame}[fragile]  \begin{frame}[fragile]
132    \frametitle{With 2 groups, we label the min and max points}    \frametitle{Label a scatterplot of the iris data by species}
133  <<echo=FALSE,results='hide'>>=  <<>>=
134  tx <- time(mdeaths)  set.seed(1)
135  Time <- ISOdate(floor(tx),round(tx%%1 * 12)+1,1,0,0,0)  irisp <- xyplot(jitter(Sepal.Length)~jitter(Petal.Length),
136  sexdf <- function(sex,x)data.frame(Time,sex,deaths=as.integer(x))                  iris,groups=Species)
137  uk.lung <- rbind(sexdf("male",mdeaths),sexdf("female",fdeaths))  direct.label(irisp)
138  @  @
139    \end{frame}
140    
141    
142    \begin{frame}[fragile]
143      \frametitle{Label a scatterplot of the iris data by species}
144    <<dev='png'>>=
145    set.seed(1)
146    library(ggplot2)
147    p <- ggplot(iris,aes(jitter(Sepal.Length),jitter(Petal.Length)))+
148      geom_point(aes(colour=Species))
149    source("iris-images.R")
150    pimg <- p+
151      GeomImageLabel$new(aes(label=Species),
152                          method=find.empty.box,
153                          images=iris.photos)
154    library(directlabels)
155    direct.label(pimg)
156    @
157    \end{frame}
158    
159    
160    
161    
162    \begin{frame}[fragile]
163      \frametitle{Construct your own custom Positioning Method}
164  <<>>=  <<>>=
165  p <- xyplot(deaths~Time,uk.lung,  rp2 <- ratplot+
166              groups=sex,type=c("l","g"))    xlim(0,70)+ylim(150,650)
167  direct.label(p)  big.last <- list(cex=1.5,"last.qp")
168    direct.label(rp2,"big.last")
169  @  @
170  \end{frame}  \end{frame}
171    
172    \begin{frame}[fragile]
173      \frametitle{Construct your own custom Positioning Method}
174    <<>>=
175    direct.label(rp2,
176      list("big.last",
177           "calc.boxes",
178           "draw.rects"))#p
179    @
180    \end{frame}
181    
182    \begin{frame}[fragile]
183      \frametitle{Construct your own custom Positioning Method}
184    <<>>=
185    spaced.last <- list(last.points,cex=1.5,calc.boxes,
186                        dl.trans(h=h+h/3),calc.borders,
187                        draw.rects,qp.labels("y","h"))
188    direct.label(rp2,spaced.last)
189    @
190    \end{frame}
191    
192    
193    
194    
195    
196  % 3---- examples: ... writing custom methods?  % 3---- examples: ... writing custom methods?
# Line 135  Line 204 
204  % lasso plot: add lasso.labels as well!  % lasso plot: add lasso.labels as well!
205  % http://directlabels.r-forge.r-project.org/docs/lineplot/plots/lars.html  % http://directlabels.r-forge.r-project.org/docs/lineplot/plots/lars.html
206    
207    \frame{\tableofcontents}
208  \section{Recent developments in direct labeling}  \section{Recent developments in direct labeling}
209    
210  \begin{frame}  \begin{frame}
# Line 172  Line 242 
242  % - generating a website using plots and methods defined in the R  % - generating a website using plots and methods defined in the R
243  % package.  % package.
244    
245    \frame{\tableofcontents}
246  \section{Conclusions}  \section{Conclusions}
247    
248  \begin{frame}  \begin{frame}[fragile]
249    \frametitle{What directlabels is NOT}    \frametitle{What directlabels is NOT}
250    
251    \begin{itemize}    \begin{itemize}
252    \item Automatic publication-quality direct labels.    \item Automatic publication-quality direct labels.
253        \\ (some manual tweaking will always be necessary)
254    \item Optimal labels for individual points on scatterplots.    \item Optimal labels for individual points on scatterplots.
255        \\ (it is a bit more complicated:)
256    \end{itemize}    \end{itemize}
257    <<echo=FALSE,results='hide'>>=
258    source("pointLabel.R")
259    # Examples:
260    set.seed(100)
261    n = 50
262    x = rnorm(n)*10
263    y = rnorm(n)*10
264    plot(x,y, col="red",pch=20)
265    pointLabel(x, y, as.character(round(x,5)), offset = 0,
266               allowSmallOverlap = F,cex=.7, trace = TRUE)
267    @
268  \end{frame}  \end{frame}
269    
270  % - directlabels is useful for everyday data visualization, but some  \begin{frame}
271  % manual tweaking can help make a publication-quality figure.    \frametitle{Use directlabels instead of confusing legends!}
272    
273  % - future work in image labels?    \begin{itemize}
274      \item directlabels is useful for everyday data visualization.
275        \begin{itemize}
276        \item It works with lattice and ggplot2,
277        \item has sensible defaults,
278        \item smart Positioning Methods that avoid label collisions,
279        \item and you can write your own Positioning Methods!
280        \end{itemize}
281      \item Future work:
282        \begin{itemize}
283        \item Automatically adjust xlim/ylim so labels stay on plot region?
284        \item Contourplot labels as in \texttt{contour()}?
285        \item Label using images instead of textual factor names?\\
286          Possible Google Summer of Code 2012 project:\\
287          {\scriptsize \url{http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2012}}
288        \end{itemize}
289      \end{itemize}
290    \end{frame}
291    
292  \end{document}  \end{document}

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

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