Monthly Archive for February, 2008

Converting between SVG, EPS, and PDF

Sometimes you want to be able to tweak a plot in R that was saved as a PDF or an EPS.

Use this to convert an eps into svg for editing in Inkscape:

pstoedit -f plot-svg input.eps output.svg

Then save the SVG in Inkscape as a “Plain SVG”, and use

convert input.svg output.pdf

Change properties of ggplot plots

Try

?ggopt

to see the different ways of adjusting plot background, axes, aspect ratio, border colors, and strip labels.

Change the font size of the labels.

This acts on the currently active plot.

grid.gedit('label', gp=gpar(fontsize=16))

Or just change one type of label (here, the yaxis).

grid.gedit(gPath("yaxis", "labels"), gp=gpar(col="red"))

Use a black and white theme

The newest version of ggplot2 (0.5.7) allows you to have black and white themes.

pl = ggplot(diamonds)+aes(x=carat, y=price) +
    geom_point()+theme_bw
pl

I like to tweak the theme_bw a little before using it as above:

theme_bw$grid.colour = "grey80"
theme_bw$border.colour = "gray70"

Change the strip labels

pl$strip.gp = gpar(fill="grey90")
pl$strip.txt.gp = gpar(col="black", fontsize=16)
pl

Change factor colors to grayscale

pl+scale_colour_grey(end=0.7,start=0,name='')
pl

Combine dataframes in R

Quick answer: use merge.

You can also use rbind, but it will only be useful for simple cases.

See http://www.statmethods.net/management/merging.html for more details.