# Holcombe:Plotting

(Difference between revisions)
 Revision as of 17:22, 12 March 2011 (view source) (→polishing plots)← Previous diff Revision as of 17:23, 12 March 2011 (view source) (→polishing plots)Next diff → Line 42: Line 42: theme_bw() #see associated list of options theme_bw() #see associated list of options p + opts( axis.text.x= theme_text(size = base_size * 0.8 , lineheight = 0.9, colour = "grey50", hjust = 1, angle = 90) ) p + opts( axis.text.x= theme_text(size = base_size * 0.8 , lineheight = 0.9, colour = "grey50", hjust = 1, angle = 90) ) - p+opts(legend.key=theme_rect(fill="blue",colour="white")) + p+opts(legend.key=theme_rect(fill=NULL,colour="white")) + ok

## Revision as of 17:23, 12 March 2011

### Members

Alex Holcombe
Sarah McIntyre
Fahed Jbarah
• Shih-Yu Lo
• Patrick Goodbourn
Lizzy Nguyen
Alumni

### Other

Good advice on graph choice, from human perceptual standpoint by Frank Harrell

## ggplot2

In the lab we usually use the R package, ggplot2, for graphs. Ask Sarah about the ggplot2 book.

For custom colour schemes, the Chart of R Colors is a helpful resource. The table with named colours is most useful.

ggplot2 tips:

#where 'g' is your ggplot object
str(g)  #gives you everything!
summary(g) #gives a summary
options(g) #lists the options
last_plot() #refreshes the last plot and returns the struct
p=p+scale_y_continuous(breaks=c(0,0.5,1),minor_breaks=c(.25,.75)) #changing axis breaks
p=p+opts(title="one-behind errors")
p=p+xlab('relative phase')
opts(panel.grid.minor = theme_blank())+
last_plot() + opts(panel.grid.minor = theme_line(colour = "black") )
facet_grid(.~subject)  # rows~columns
g<-g+stat_summary(fun.y=mean,geom="point",position="jitter") #getting jitter to work when you're collapsing across other variables with stat_summary
g=g+ stat_smooth(method="glm",family="binomial",fullrange=TRUE) #adds logistic smoother to plot
#it's impossible to extract the function fits however because they're fit on the fly
#how can I fit an arbitrary function, like a psychometric function, e.g. cumulative gaussian with chance rate and lapse rate? Logistic is restricted to 0->1

order used for scale mapping (color, etc.) is perhaps the order of the levels property of the vector. This gives bizarre results because R's sort(unique(x)) default does not alphabetize strings. Getting things to appear in a graph or something the way you want may require reordering the 'levels' of a factor, like this to put DL as the last subject to be graphed:

pvalsCIs\$subject<-factor(pvalsCIs\$subject,levels=c("AH","SM","SYL","WYC","DL")) #levels(pvalsCIs\$subject)

### polishing plots

See Chapter 8 of the ggplot book

p+ theme_bw() #changes all options to those of theme_bw
theme_bw() #see associated list of options
p + opts( axis.text.x= theme_text(size = base_size * 0.8 , lineheight = 0.9, colour = "grey50", hjust = 1, angle = 90) )
p+opts(legend.key=theme_rect(fill=NULL,colour="white"))
ok