Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ajout de la liste des valeurs possibles pour pch

  • Loading branch information...
commit 877f3484f20c1a2f538f30d7e59d9888117ec88b 1 parent a265e7e
@larmarange larmarange authored
Showing with 87 additions and 0 deletions.
  1. +14 −0 intro.Rnw
  2. +73 −0 pchShow.R
View
14 intro.Rnw
@@ -1582,7 +1582,21 @@ dotchart(sort(table(d$qualif)), main="Niveau de qualification")
\label{fig_dotchartsort}
\end{figure}
+\begin{astuce}
+ L'agument \texttt{pch}, qui est utilisé par la plupart des graphiques de type
+ points, permet de spécifier le symbole à utiliser. Il peut prendre soit un
+ nombre entier compris entre 0 et 25, soit un charactère textuel
+ (voir figure~\ref{fig_pch} \vpageref{fig_pch}).
+\end{astuce}
+\begin{figure}
+<<figure_pch, echo=FALSE>>=
+source("pchShow.R")
+pchShow(c("*","+","a","x"),main="", symbolsize=2.5, linewidth=2,fillcolor="palegreen3",symbolcolor="palevioletred3")
+@
+\caption{Différentes valeurs possibles pour l'argument \texttt{pch}}
+\label{fig_pch}
+\end{figure}
\section{Exercices}
View
73 pchShow.R
@@ -0,0 +1,73 @@
+# From http://rgraphics.limnology.wisc.edu/pch.php
+pchShow <-
+ function(extras = c(".", "o", "O", "0","a","A", "*", "+","-","|"),
+ symbolsize = 3, #
+ symbolcolor = "red3",
+ fillcolor = "slateblue3",
+ linewidth = 1,
+ textcolor = "black",
+ textsize = 1.2,
+ main = paste("Plot symbols in R;\n col = \"",
+ symbolcolor, "\", bg= \"",fillcolor,"\"" )
+ )
+{
+
+ # Organize symbols & characters to be plotted
+ # --------------------------------------------------------------------------
+
+ nex <- length(extras) # number of char graphics symbols to plot
+ n_points <- 26 + nex # total number of symbols to plot
+ ipch <- 0:(n_points-1) # sequence of pch id numbers (0,1,2,...25)
+
+ # create list of pch values (0:25) ('list' allows integers & strings)
+ pchlist <- as.list(ipch)
+
+ # Add the special characters to the list (if any)
+ if(nex > 0) pchlist[26 + 1:nex] <- as.list(extras)
+
+ # Set up graphing space for display of symbols
+ # --------------------------------------------------------------------------
+ # no. of columns to display in graph
+ # (selected such that plot is close to square, nrows ~= ncols)
+ k <- floor(sqrt(n_points))
+
+ dd <- c(-1,1)/2 # padding of graph (+ 0.5 units on each side)
+
+ # x coordinates for plotting symbols ('a %% b' means 'a modulus b';
+ # that is, divides a by b and returns the remainder.)
+ ix <- ipch %% k
+
+ # y coordinates for plotting symbols ('a %/% b' indicates integer division,
+ # that is, it returns the integer portion of the quotient only)
+ iy <- 3 + ((k-1)- ipch %/% k)
+
+ rx <- dd + range(ix) # full range of x axis
+ ry <- dd + range(iy) # full range of y axis
+
+ # create plot window
+ plot(rx, ry, type="n", axes = FALSE, xlab = "", ylab = "", main = main)
+
+ # display grid lines
+ abline(v = ix, h = iy, col = "lightgray", lty = "dotted")
+
+ # Plot symbols and symbol labels (loops through each symbol type)
+ # --------------------------------------------------------------------------
+
+ for(i in 1:n_points) {
+ # for each value, i, get symbol id from list created ealier
+ pch_i <- pchlist[[i]]
+
+ # plot point at x(i), y(i), using the selected symbol.
+ # Colors and size determined above
+ # 'bg'-colored interior (only available for pch 21-25) :
+ points(ix[i], iy[i], pch = pch_i, col = symbolcolor, bg = fillcolor,
+ cex = symbolsize, lwd=linewidth)
+ if(textsize > 0)
+ text(ix[i] - .3, iy[i], pch_i, col = textcolor, cex = textsize)
+ }
+ }
+
+#pchShow()
+#pchShow(c("a","A","b","B"), symbolsize = 2.5)
+#pchShow({}, symbolsize = 4, linewidth=3)
+#pchShow(c("a","A","b","B","c", "C", "1", "2", "3", "4"), symbolsize = 2.5)
Please sign in to comment.
Something went wrong with that request. Please try again.