# Holcombe:Plotting

(Difference between revisions)
 Revision as of 18:58, 10 March 2011 (view source) (New page: {{Template:Holcombe}} Good advice on [http://biostat.mc.vanderbilt.edu/twiki/pub/Main/StatGraphCourse/graphscourse.pdf graph choice, from human perceptual standpoint] by Frank Harrell ==...)← Previous diff Revision as of 18:59, 10 March 2011 (view source)Next diff → Line 13: Line 13: str(g)  #gives you everything! str(g)  #gives you everything! summary(g) #gives a summary summary(g) #gives a summary + options(g) #lists the options last_plot() #refreshes the last plot and returns the struct last_plot() #refreshes the last plot and returns the struct

## Revision as of 18:59, 10 March 2011

### Members

Alex Holcombe
Sarah McIntyre
Fahed Jbarah
Wei Ying Chen
• Shih-Yu Lo
• Patrick Goodbourn
Lizzy Nguyen
• Esther Lee

### 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)