[R] How to make a plot?

Romain Francois francoisromain at free.fr
Tue Dec 13 18:05:36 CET 2005


Le 13.12.2005 14:32, Gabor Grothendieck a écrit :

>Does anyone have an idea of how to make a chart in R like the
>ones here that use a graphic:
>
>http://bigpicture.typepad.com/comments/images/slide1.gif
>  
>
Hi Gabor,

Here's a first draft.

The following code will produce a pdf (i only found transparancy support 
in pdf devices) which will be converted afterwards into a png file using 
(thanks to imageMagick) :

$ convert output.pdf output.png

Everything is there :
http://addictedtor.free.fr/misc/gabor/
Background image : http://addictedtor.free.fr/misc/gabor/cruise.pnm
Code : http://addictedtor.free.fr/misc/gabor/gabor.R
Pdf output : http://addictedtor.free.fr/misc/gabor/output.pdf
Png output : http://addictedtor.free.fr/misc/gabor/output.png

Romain

Code :
#########################################
require(pixmap)
require(grid)

x <- read.pnm('cruise.pnm')

pdf('output.pdf', width=6, height=4, version="1.4")

par(mar=c(0,0,0,0))

plot(x) # base graphics

y <- c(6, 6.5, 7, 8, 8.5, 8.2, 10, 9.6, 9.7, 9)
# some data like in the picture you gave


# now the grid stuff

pushViewport(viewport(xscale=c(0,10),
                      yscale=c(0,10)))

grid.rect(x=0:9,
          y=0,
          width=1,
          height=y,
          default.units="native",
          gp=gpar(fill="white", alpha=0.7, col="gray", lwd=2),
          just=c("left","bottom"))

grid.rect(x=0:9,
          y=y,
          width=1,
          height= unit(1, "npc") - unit(y, "native") ,
          default.units="native" ,
          gp=gpar(fill="white", col="white"), just=c("left","bottom"))

grid.lines(x=c(0,10), y=c(5, 5), default.units="native", gp=gpar(lwd=2, 
col="white", lty="dotted"))
 
grid.lines(x=c(0,10), y=c(10, 10), default.units="native", 
gp=gpar(lwd=2, col="gray", lty="dotted"))

popViewport()


dev.off()

#################################################


-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr               |
| Doctorant INRIA Futurs / EDF                                  |
+---------------------------------------------------------------+




More information about the R-help mailing list