Tuesday, November 24, 2015

R: MIssing legend when using scale_fill_manual

When configuring ggplot using scale_fill_manual in R, sometimes the legend might not be displayed. This happens when we specify 'breaks' property within the scale_fill_manual command, and the values we supply don't correspond to the factor levels we use in fill.

For instance, assume we have a data frame with columns 'X', 'Y', and 'Type', where 'Type' contains values 'A' and 'B'. In the below ggplot/ggplot2 command, breaks argument cannot contain a list of strings which do not map to factor levels in column 'Type':
ggplot2(data=df, aes(x=X, y=Y, fill=Type)) + 
scale_fill_manual(values=c("black","red", name="Type", breaks=c("A","B"), labels=c("Type-A","Type-B"))

Instead, we need to specify the breaks as:
ggplot2(data=df, aes(x=X, y=Y, fill=Type)) + 
scale_fill_manual(values=c("black","red", name="Type", breaks=levels(factor(df$Type)), labels=c("Type-A","Type-B"))

Or as below, if we are sure of the factor ordering:
ggplot2(data=df, aes(x=X, y=Y, fill=Type)) + 
scale_fill_manual(values=c("black","red", name="Type", labels=c("Type-A","Type-B"))

References:
1. http://stackoverflow.com/questions/14546858/missing-legend-when-combining-scale-fill-manual-and-scale-x-discrete-in-bar-char

Wednesday, September 23, 2015

Windows 7 Safe mode - Starting "Run Installer" and "Print Spooler" services

Windows Installer will not work under Safe Mode, this means that programs cannot be installed or uninstalled in safe mode without giving a specific command using msiexec in command prompt.

To make Windows Installer work under safe mode, you need to create a registry entry for every type of safe mode you are logged in to.

Run these commands from command line:
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer" /VE /T REG_SZ /F /D "Service"

net start msiserver 


To Start Print Spooler
Method-1:
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\Spooler /VE /T REG_SZ /F /D Service

Net Start Spooler

Method-2:
Run Command prompt in administrator mode (right click and press "Run as Administrator"), and then run these commands.
Net stop spooler
sc config spooler depend= RPCSS
Net start spooler
exit

Reference:
1. http://www.symantec.com/connect/blogs/windows-installer-safe-mode
2. https://forums.techguy.org/threads/solved-enabling-print-spooler-in-safe-mode.1056317/
3. http://www.techsupportall.com/solved-print-spooler-error-1068-the-dependency-service-or-group-failed-to-start/