Place an image into an R plot

There a basically two options on how to place arbitrary images as a point symbol into a plot in R. If you want to use a raster images such as GIF, JPG or BMP, opt for the “pixmap” package.  You will have to convert your image into the PPM format and then use the “add_logo” function of the package. An example usage is given here or here. However, the result will often not render nicely.

An alternative is to import vector graphics such as SVG or PS using the “grImport” package (Vignette). Suppose you have a postscript graphics named “candle.ps” (if you have an SVG graphics, then use e.g. Inkscape to convert SVG to PS), the following gives the desired plot:

## Read postscript
library(grImport)
PostScriptTrace("candle.ps")
ca = readPicture("candle.ps.xml")

## Set up some points and set background color
library(lattice)
library(grid)
N = 22; x = seq(9,N*10,9); y = rnorm(N, 40, 30)
trellis.par.set("background", list(col = "#380000"))

## Plot with lattice function
xyplot(y~x , xlim=c(0, 9*N + 5), ylim=c(20,100),
panel = function(x, y, ...) {
grid.symbols(ca, x, y, units = "native", size = unit(13, "mm"))})

The result could look like this:

Candle Plot

Please note two things. First, postscript does not support transparency. It might be necessary that you replace transparent colors with solid colors using Inkscape, for example. Furthermore, grImport does not paint on the default “base” graphics system (functions like plot, hist), but only on the “grid” graphics system. Therefore we use “lattice” to produce graphics, as the package utilizes grid graphics. These slides from package creator Paul Murell are an helpful further reading.

Best Free Offline Maps Application for Android

I wanted to use my Android device for GPS offline mapping to avoid paying excessive roaming fees abroad. It turned out that is not only difficult to filter the appropriate maps app out of dozens which are available on the Android Market (an overview is given here), but also that there are only few usable solutions. Usable means: simple, fast and bug-free. Here is what I recommend.

As far as I know, there is only a single free app which you can just install and go: MapDroyd. After installing you select the regions for which you want offline maps. The program then downloads them automatically. The app uses its own format for Maps (MicroMap Format) optimized for mobile devices. Since it uses vectorized data the maps are not large. However, the program only shows the map – no navigation nor POIs. If you are willing to pay a few dollars, there is a version supporting navigation called NavDroyd.

If you want both for free, you should opt for OsmAnd. It provides navigation, search for addresses and POIs. The latter can be downloaded from within the program. The drawback is that you have to create the maps manually and load them on your android device beforehand (HowTo). You can use the free tool MobileAtlasCreator to do so. Also download this Java Library and store it in the same directory as the Creator. The program lets you select the area which you want the maps for as well as the source of the mapping data (OSM Mapnik recommended). Since it uses tiled images which have to be created for different zoom levels, maps tend to be much larger than for vectorized data.  I used zoom levels 0 to 16. Note that the size of zoom level 16 images is bigger than 0 to 15 together and that OsmAnd interpolates +2 zoomlevels from a smaller one. Do not forget to press Add Selection in the MobileAtlasCreator and to select Big Planet Tracks SQLite Format – it will save you huge amounts of effective space  on the SD card. Warning: Map download and creation will probably take up to some hours, depending on the map size.

There is one free App that can do above using vectorized maps, Navit, but it is not available on the market yet and must be inconveniently installed by hand (german instructions here).

Note: I will update this post after having used both tools abroad.

Laos Photos

IMG_0871Here are some impressions from our inspiring trip to Laos.

.

.

Read more »

The Latticist Package for R

One of my dear readers, C S,  has pointed out to me the R package latticist. In the beginning I was sceptical, since the package is merely more than an interface to existing visualization routines. However, I now consider it astonishingly useful and use it almost every day. The reason is simple: Getting an intial glimpse onto a large set of multivariate data is tedious in R, due to the command line interface. With latticist, you get an instant overview over all variables of interest and it allows you to quickly dive into details by selecting subgroups and to look at potential correlations. Recommended.

Project Organization Advice

Have you ever had the problem of re-finding how you created this particular image or that specific result of your recent bioinformatics project? I did, and not only once.  In his article “A quick guide to organizing computational biology projects“, the distinguished scientist William S. Noble gives great advice on how to organize a research project practically. His key suggestions include:

  • use a date-based directory structure for the experiments you perform
  • keep a lab-notebook containing documentation and code for each experiment (How about Org-mode?)
  • create generate scripts that work on original data and a general runner script for the complete experiment

His work flow is applies mostly to *nix enviroments. One thing I’d like to add: Use symbolic links! Due to huge amounts of data and backup strategies, it might be impractical to have all the project’s data in a single directory. Create subdirectories of your data and result directories according to the naming convention and link them to other network drives using the ‘ln -s’ command.

Free Photo Backup to Windows Skydrive

One of my greatest fears is loosing my photo collection, those irretrievable links to good memories. Other physical media (CD, HD) to be stored at home aren’t save either, therefore I’d like to have an online backup solution. Windows Live Skydrive features 25GB free storage for files up to 50MB size. Using the free tool SDExplorer you can also upload your own photo folder structure to the Skydrive. Alternatives are Gladinet (but the free version allows only 1000 files to be uploaded!) and Windows Live Photo Gallery (each folder has to be uploaded indivually, no subfolders).

Python Recipe: Read CSV/TSV Textfiles and Ignore Comment-lines

Scientific data commonly comes in tab-separated textfile format containing comment lines. What is the best way to read this data? Analogous to the recipe given by skip.montanaro, use a commented file decorator as follows:

import sys, re
import csv
class CommentedFile:
    def __init__(self, f, commentstring="#"):
        self.f = f
        self.commentstring = commentstring
    def next(self):
        line = self.f.next()
        while line.startswith(self.commentstring):
            line = self.f.next()
        return line
    def __iter__(self):
        return self

tsv_file = csv.reader(CommentedFile(open("inputfile.txt", "rb")),
                      delimiter='\t')
for row in tsv_file:
    print row[2] # prints column 3 of each line

A Reload-Button in Adobe Acrobat

Read this post about how to reload your pdf document. This is particularly useful when you are creating a new document with LaTeX. Sweet, I was waiting for that functionality.

Kochmesser Schnäppchen

Ein jeder (Hobby-)Koch benötigt ein gutes Kochmesser. Im Weblog Lifehacker wurde vor kurzem ein Messer empfohlen welches eine sehr gute Qualität besitzt, aber statt 100-200$, wie vergleichbare Produkte, nur rund 30$ kostet. Das vom schweizerischen Hersteller Victorinox hergestellte Messer scheint jedoch in dieser Form nur in Amerika erhältlich. Zumindest fand ich es im europäischen Victorinox Katalog nicht wieder. Bei Amazon.com ist es immerhin das meistverkaufteste Messer.

Auf Nachfrage bei Victorinox erhielt ich aber die Information das es in Europa ebenfalls vertrieben wird – nur mit leicht anderem Bedruck. Die Artikelnummer ist  5.2063.20. Ich habe es bereits gekauft und es macht einen guten Eindruck.

Use the new Emacs Daemon!

Emacs usually takes quite some time to fully start up. However, as described in the great blog Emacs-Fu, Emacs 23 can now be started in the background as a daemon. This allows to fire up a new Emacs instance really fast. Thanks djcb!