Categories
status

Surround a VIM plugin that surrounds a word…

Surround, a VIM plugin that surrounds a word or a line.

http://www.catonmat.net/blog/vim-plugins-surround-vim/

Categories
status

Perl Getopt Long The module check wrong argument…

Perl Getopt::Long.

The module check wrong argument but does not check when no argument is provided.
In order to check if there is no argument as well as wrong argument,
check the argument also.

GetOptions( 'test=s' => \$option_test )
    or exit(1);

defined($option_test)
    or die("Missing argument -t");

http://www.perlmonks.org/?node_id=789974

Categories
status

Auto size of images in Beamer class \usepackage…

Auto size of images in Beamer class.

\usepackage{letltxmacro}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\makeatother
\AtBeginDocument{
  \LetLtxMacro\Oldincludegraphics\includegraphics
  \renewcommand{\includegraphics}[2][]{%
    \Oldincludegraphics[#1,width=\maxwidth]{#2}}
}

http://tex.stackexchange.com/questions/67434/redefine-includegraphics-for-beamer#comment143600_67434

Categories
status

Beamer paper size is smaller than usual paper…

Beamer paper size is smaller than usual paper size.
The “paper size” of a beamer presentation is fixed to 128mm times 96mm.

With this trick, the normal font can be shown nicely.
But be cautious setting the image size with absolute value.
or use

\includegraphics[width=0.6\textwidth]{graphics.pdf}

http://web.mit.edu/8.13/presentations/beameruserguide.pdf

Citation

Categories
status

R color palettes # Basic grDevice rainbow topo…

R color palettes

  1. Basic grDevice

rainbow()
topo.colors()
terrain.colors()
heat.colors()

my.palette <- terrain.colors(100)
  1. RColoBrewer package
display.brewer.all()

my.palette <- brewer.pal(n, name) For example, my.palette <- brewer.pal(9, "Blues") However, the number of colors is limited up to 9, in most colors. Then use this.

more.color.palette <- colorRampPalette(brewer.pal(9,"Blues"))(100)

http://stackoverflow.com/questions/3832850/color-schemes-in-r
http://www.compbiome.com/2010/12/r-using-rcolorbrewer-to-colour-your.html

Categories
status

RColorBrewer palette names

RColorBrewer palette names.

Categories
status

Change the label of legend not by changing…

Change the label of legend not by changing the data.

# data
grp <- gl(n=4,k=20,labels=c("group a","group b","group c", "group d"))
value <- runif(n=80, min=10, max=150)
outcome <- cut(value,2)
data <- data.frame(grp,value,outcome)

# Option 1
# breaks should be exactly the same as the levels of the factor
ggplot(data, aes(grp, fill=outcome)) + geom_bar() +xlab("group") +
    ylab("number of subjects") + 
    scale_fill_discrete("Serologic response", 
                        breaks=c("(12.1,79.7]","(79.7,147]"),   # should be the same as the levels of the factor
                        labels=c("double negative", "positive for a and/or b")
                        )

# Option 2
# simpler because factor() takes care of the levels of the factor
ggplot(data, aes(grp, 
         fill=factor(outcome,labels=c("double negative","positive for a")))) + 
    geom_bar() +xlab("group") +ylab("number of subjects") +
    labs(fill="Serologic response")

http://stackoverflow.com/questions/7323191/how-do-i-manually-change-the-key-labels-in-a-legend-in-ggplot2

Categories
status

R factors levels labels # sample data originally…

R factors, levels, labels

# sample data originally numbers
# 1 = male, 2 = female

people.n <- c(1, 1, 2, 2, 2)
people.c <- c("male", "male", "female", "female", "female")

# create a factor
people.n.f <- factor(people.n, levels = c(1, 2), labels = c("male", "female"))
people.c.f <- factor(people.c, levels = c("male", "female"), labels = c("male", "female"))

# if you want to change the order of the levels, 
people.n.f <- factor(people.n, levels = c(2, 1), labels = c("female", "male"))

# levels follows alphabetical order if not specified
# compare this with people.c.f
factor(people.c)

# without specifying levels and labels
# the original data will be used
factor(people.n)

# once used to create a factor, levels and labels are merged.
# there is no labels attribute in factor.
# correct
levels(people.c.f)
levels(people.c.f) <- c("man", "woman")
people.c.f

#wrong
labels(people.c.f)
labels(people.c.f) <- c("man", "woman")

Conclusion
By default, factor() order the levels alphabetical order or numerical order.
If you want to change the sorting order of levels manually, you need to set it when the factor is created.
It can not be changed later, even though the levels can be changed.

When creating a factor, the data and the order should be matched as the example.

factor(people.c, levels = c("male", "female"), labels = c("male", "female")) 
          ^ ---- same data ---------^    ^-------------same order -----^

Categories
status

Search hg Mercurial log and repository Search for…

Search hg (Mercurial) log and repository.

Search for a file

hg log file.pl

Search the list of tags

hg tags

Search log of a tag

hg log -r ver1
  1. tag is very much like a revision number.

Search a word in the log summary

hg log -k keyword

Search a log history of a file

hg log file.pl

Search a code history of a file

hg annotate file.pl
Categories
status

Search for logs by date range in Mercurial…

Search for logs by date range in Mercurial

hg log –date “2012-07-01 to 2012-7-31”