A Happy New Year from R and ggplot2

Here is a happy new year picture from R and ggplot2.

Continue reading


Using jet colormap in R and ggplot2

The jet colormap is widely used (at least in my research community).

Continue reading

FAQ: How to order the (factor) variables in ggplot2

When you make a bar plot for categorical (i.e., factor) variables, probably you want to order the levels of variable in some way.

Continue reading

FAQ: geom_line() doesn’t draw lines

Probably one of the most frequently asked question is that geom_line() does not draw lines.
This is because x variable is factor.

Continue reading

Use image for background in ggplot2

ggplot2 does not support drawing image files by default, but it is easy to draw images for background using ggplot2.

Continue reading

Plot mts (multivariate time series) in ggplot2


ggplot2 does not support ts plot by default, but easily plot after brief data transformation.

Continue reading

Draw function without data in ggplot2

Sometimes I need to draw mathematical functions only by specifying the xlim and without read data.
stat_function() can handle this.


Basic form is:

qplot(c(0, 2), stat="function", fun=exp, geom="line") 
# or
ggplot(data.frame(x=c(0, 2)), aes(x)) + stat_function(fun=exp)

Continue reading