Blog

  • Change the label of legend not by changing…

    ce site 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

  • 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 -----^
    

  • 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
    
  • 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”

  • LaTeX subcaption package http www tug org texlive…

    LaTeX subcaption package.

    http://www.tug.org/texlive/Contents/live/texmf-dist/doc/latex/caption/subcaption.pdf

  • Quicklook like preview for Windows 7 I miss…

    Quicklook like preview for Windows 7
    I miss a lot of QuickLook of Mac OS X while using Windows.
    Windows 7 has a Preview Pane. With a keyboard short cut, it is comparable to QuickLook.
    Alt-P is the key for turning on/off the Preview Pane.

    http://productivity.ben61a.com/windows/windows-7-shortcut-keys.php

  • Change resolution of Powerpoint when export into image…

    Change resolution of Powerpoint when export into image

    The default is 96 dpi which is not enough for printing.
    Follow this instruction to change it to 300 dpi.

    http://support.microsoft.com/kb/827745

  • Windows explorer preview locks file Explorer of Windows…

    Windows explorer preview locks file.

    Explorer of Windows has Preview pane. It is nice but as a default, it locks the file in preview.
    Which means, the file can not be modified, renamed, or saved.
    To change the behavior, add a value to the Windows registry according to this instruction.

    http://support.microsoft.com/kb/942146

  • VIM search tip In addition to or there…

    VIM search tip.

    In addition to / or ? there are more search options.

    • or # search the exact word under the cursor.

    (g* or g# search the words including the word under the cursor.)

  • http stevelosh com blog 2009 08 a guide…

    http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/