Analyses and Visualization of Typhoon in R and ggplot2 #1: The basics


台風が来そうで来ない@関東。

Rでの解析の一例として、台風の軌道とか強さとかを処理してみよう。
台風のデータは実験心理学のデータに近いので、その手の解析には応用できると思います。

Continue reading

Alpha version of colorbar legend in ggplot2


The examples below show colorbar legends in ggplot2.

Please note that this is alpha version and it is not sure if this implementation appears in the future version of ggplot2.

I’m happy if you play with this function and report potential bugs and missing functions.

To test this, you need install Hadley’s scales package and my implementation based on Hadley’s ggplot2.

Here is a direct link to the tarball:

The colorbar is controlled by passing the legend_param argument to scale_{fill, colour}_XXX. XXX needs to be continuous family, e.g., discrete, etc.

The legend_param needs to be a list. Currently three elements is available.

  1. colorbar (logical): draw colorbar if TRUE.
  2. colorbar_nbin (integer): the number of division of colorbar, i.e., the resolution of the colorbar default: approx. 20).
  3. colorbar_nbreaks (integer): the number of breaks of the colorbar (default: approx. 5).

The size of colorbar is controlled by theme – legend.key.size, legend.key.width, and legend.key.height.

The breaks and labels can be controlled via breaks and labels arguments in scale_*, this is same as normal legend.

Continue reading

Japanese stock market in 2011


ニュースを見ていたら、うさぎ年は株価が上がるという報道があった。ちょうどいいので、プロット&スタッツ。仮説検定とか時代遅れですいません。

分布とQQプロット

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