What about privacy ? :)

Sign by Danasoft - For Backgrounds and Layouts

Visualizzazione post con etichetta r-project. Mostra tutti i post
Visualizzazione post con etichetta r-project. Mostra tutti i post

martedì 16 aprile 2013

LATTICE package intro

This post is a sort of pro-memoria where I wrote down the main concepts of one chapter of the Murrel book reported in the bibliography, at the end of the post. The LATTICE package implements the Trellis graphic system, you can find information here.
It is based on the "grid system" of plotting (not on the "base system"). Anyway, it can be used without tackle any of the underlying grid concepts. In fact, it is also a self-contained system with a set of functions for:
  • producing complete plots;
  • controlling the appearance;
  • opening/closing devices.
Lattice functions produce an object of class "trellis", containing a descriprtion of the plot. The actual draw is performed by the print() function.

tpl <- xyplot(lat ~ long, data=quakes) # creates a trellis object
print(tpl) # draw it

Now it is possible to modify the trellis object through the update() method, which is an alternative to modifying the original R expression used to create the trellis object.

update(tplot, main="This is a Title\n(write what you prefer)") # insert a title

Note:
  • A subtle change: extra space introduced to allow room for adding the new main title.
  • this change is not retained: ion order to retain it you should assign to the object
tplot <- update(tplot, main="This is a Title\n(write what you prefer)") # insert a title


Different devices have different default settings (e.g.: PDF has different settings compared to PNG). The first time that a lattice output is produced the settings are initialized (type ?trellis.device() ).
The graphical appearance of lines type and colors, text fonts etc. are maintained for each device opened (more on next posts). Default settings of Trellis Graphics produced through Lattice are carefully selected in order to maximize the
readability based on principles of human perception.

Bibliography
Murrell. P., R Graphics, 2005 by Chapman and Hall/CRC ( Murrel book web page )

lunedì 17 dicembre 2012

How to change (a lot of) system file names with R


Imagine you need to change (a lot of) file names for you work or simply to rename you music files collection.
I wrote a code that does the job with the programming language R (www.r-project.com) as you can see in the following:

# first set your working directory
setwd("~/my_directory")

# read file names and store them in an object (created on the fly)
(listafiles<- list.files())

#inspect the just created object
head(listafiles)
str(listafiles) #246 elementi
grep(pattern="[2011]", listafiles) #246 nomi contengono 2011 (365-246=119 giorni mancanti)

TO BE CONTINUED .....

#final check
head(listafiles,15)
head(lista_new,15)
tail(listafiles)
tail(lista_new)
nchar(listafiles)
nchar(lista_new)
sum(is.na(lista_new))