[R] Greyed text in the background of a plot

Yihui Xie xieyihui at gmail.com
Fri Sep 12 16:38:06 CEST 2008


Well, his talk seems to have attracted a lot of people... You may
simply use gray text in your plot. Here is an example:

##################################################
x = runif(10)
y = runif(10)
z = runif(10, 0.1, 0.3)
cl = rgb(runif(10), runif(10), runif(10), 0.5) # transparent colors!
par(mar = c(4, 4, 0.2, 0.2))
for (i in 1917:2007) {
   x = x + rnorm(10, 0, 0.02)
   y = y + rnorm(10, 0, 0.02)
   z = abs(z + rnorm(10, 0, 0.05))
   plot(x, y, xlim = c(0, 1), ylim = c(0, 1), type = "n", panel.first = {
       grid()
       text(0.5, 0.5, i, cex = 5, col = "gray") # here is the text!
   })
   symbols(x, y, circles = z, add = T, bg = cl, inches = 0.8)
   box()
   Sys.sleep(0.2)
}
##################################################

Not difficult at all, right? :)

BTW, if you are interested in such animations, you may as well take a
look at my "animation" package:
http://cran.r-project.org/web/packages/animation/index.html
http://animation.yihui.name/

Regards,
Yihui
- Show quoted text -

On Fri, Sep 12, 2008 at 8:35 PM, Agustin Lobo <aloboaleu at gmail.com> wrote:
> Hi!
>
> Is there any way of having a greyed ("ghosted") text
> (i.e, 2006) in the background of a plot?
> I'm making a dynamic plot and would like to show the
> year of each time step as a big greyed text in the background.
>
> (the idea comes from Hans Rosling video:
> http://video.google.com/videoplay?docid=4237353244338529080&sourceid=searchfeed
> )
>
> Thanks
>
> Agus
> --
> Dr. Agustin Lobo
> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
> LLuis Sole Sabaris s/n
> 08028 Barcelona
> Spain
> Tel. 34 934095410
> Fax. 34 934110012
> email: Agustin.Lobo at ija.csic.es
> http://www.ija.csic.es/gt/obster
>

--
Yihui Xie <xieyihui at gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China



More information about the R-help mailing list