-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.R
49 lines (46 loc) · 1.39 KB
/
functions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Create nice R figures with minimal margins
# in landscape format suitable for slides and papers
savepdf <- function(file, width=16, height=10)
{
fname <<- paste("figs/",file,".pdf",sep="")
pdf(fname, width=width/2.54, height=height/2.54, pointsize=10, bg='white')
par(mgp=c(2.2,0.45,0), tcl=-0.4, mar=c(3.3,3.6,1.1,1.1))
}
# Crop pdf to remove all white space
endpdf <- function()
{
#dev.off()
crop::dev.off.crop(fname)
}
# Histograms
gghist <- function(data, mapping, ...)
{
x <- data[[as.character(mapping$x[2])]]
bw <- 0.2*bw.nrd0(x) + 0.8*bw.SJ(x)
p <- ggplot(data, mapping) +
geom_density(col=NA, fill="#cc5900", bw=bw)
return(p)
}
# Function to produce very basic table, no lines or headings
baretable <- function(tbl, digits = 0,
include.colnames=FALSE, include.rownames=FALSE,
hline.after=NULL,
size = getOption("xtable.size", NULL),
add.to.row = getOption("xtable.add.to.row", NULL),
...) {
tbl %>%
xtable::xtable(digits = digits, ...) %>%
print(
include.colnames = include.colnames,
include.rownames = include.rownames,
hline.after = hline.after,
comment = FALSE,
latex.environments = NULL,
floating = FALSE,
size=size,
add.to.row=add.to.row,
sanitize.text.function = function(x) {
x
}
)
}