-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathFamAgg_hexSticker.R
108 lines (95 loc) · 3.96 KB
/
FamAgg_hexSticker.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
library(ggplot2)
library(png)
library(grid)
library(hexSticker)
library(hexbin)
## Settings:
col_bg <- "#663399" ## rebeccapurple
col_border <- "#bf55ec" ## Medium Purple
col_text <- "#ffffff" ## white
col_ped <- "#ffffff"
## col_ped <- "#000000"
n_steps <- 30
## Upper rectangle
y_min <- 0.95
y_max <- 1.3
x_min <- 0.1
x_max <- 1.8
alpha_max <- 0.3
## alpha_max <- 0.5
## Create the pedigree - workaround since I don't know how to add a standard
## plot to a ggplot - create the plot, save it as png and load that.
library(FamAgg)
data(minnbreast)
## Subsetting to only few families of the whole data set.
mbsub <- minnbreast[, ]
mbped <- mbsub[, c("famid", "id", "fatherid", "motherid", "sex")]
## Renaming column names.
colnames(mbped) <- c("family", "id", "father", "mother", "sex")
## Add the cancer trait.
fad <- FAData(pedigree=mbped)
tcancer <- mbsub$cancer
names(tcancer) <- mbsub$id
trait(fad) <- tcancer
png("pedigree.png", width = 4, height = 3.5, units = "cm", res = 300,
pointsize = 3)
par(bg = "NA", col = col_ped, col.lab = col_ped,
col.axis = col_ped, fg = col_ped)
plotPed(fad, family="173", col = col_ped)
dev.off()
## Alternative families:
## 13, 432, 285, 173, 262
## plotPed(fad, family = "13")
## plotPed(fad, family = "173")
## plotPed(fad, family = "262")
img <- readPNG("./pedigree.png")
## Add alpha channel.
img_a <- matrix(rgb(img[,,1], img[,,2], img[,,3], img[,,4] * 0.6),
nrow = dim(img)[1])
## g_img <- rasterGrob(img_a, width = 0.65, x = 0.48, interpolate = TRUE)
g_img <- rasterGrob(img_a, width = 1, x = 0.48, y = 0.49, interpolate = TRUE)
## Rectangle with color shade to transparency
ys <- seq(y_min, y_max, length.out = n_steps + 1)
alpha_steps <- seq(from = 0, to = alpha_max, length.out = n_steps)
trans_df <- data.frame(xmin = x_min, xmax = x_max, ymin = ys[-length(ys)],
ymax = ys[-1], alpha = alpha_steps)
trans_rect <- geom_rect(data = trans_df, fill = col_bg,
aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax,
alpha = alpha))
gg <- ggplot() +
geom_rect(aes(xmin = 0, xmax = 1.5, ymin = 0, ymax = 1.5), fill = NA) +
annotation_custom(g_img, xmin = -0.02, ymin = -0.15) +
trans_rect +
theme_void() + guides(alpha = FALSE)
## print(gg)
sticker(gg, package="FamAgg", p_size = 9, s_x = 0.99, s_y = 1.01, s_width = 1.5,
s_height = 1.5, p_color = col_text, h_fill = col_bg,
h_color = col_border, filename="FamAgg.png", p_family = "Aller_Lt",
u_color = col_border, url = "www.bioconductor.org")
set.seed(123)
sticker(gg, package="FamAgg", p_size = 9, s_x = 0.99, s_y = 1.01, s_width = 1.5,
s_height = 1.5, p_color = col_text, h_fill = col_bg, spotlight = TRUE,
h_color = col_border, filename="FamAgg_hl.png", p_family = "Aller_Lt",
l_x = 1.01, u_color = col_border, url = "www.bioconductor.org")
##################
## Old version with manual highlight.
## Highlight:
## set.seed(123)
## vals_x <- rnorm(50000, sd = 2, mean = 0)
## vals_y <- rnorm(50000, sd = 20, mean = 0)
## whiteTrans <- function(n) {
## rgb(r = rep(1, n), g = rep(1, n), b = rep(1, n),
## alpha = seq(0, 0.20, length.out = n))
## }
## hgl <- hexbinplot(vals_x ~ vals_y, colramp = whiteTrans, colorkey = FALSE,
## bty = "n", scales = list(draw = FALSE), xlab = "", ylab = "",
## border = NA, par.settings = list(axis.line = list(col = NA)))
## gg <- ggplot() +
## geom_rect(aes(xmin = 0, xmax = 1.5, ymin = 0, ymax = 1.5), fill = NA) +
## annotation_custom(g_img, xmin = -0.02, ymin = -0.15) +
## trans_rect +
## geom_subview(hgl, x = 0.9, y = 0.2, width = 3, height = 3) +
## theme_void() + guides(alpha = FALSE) + theme(axis.line=element_blank())
## sticker(gg, package="FamAgg", p_size = 9, s_x = 0.99, s_y = 1.01, s_width = 1.5,
## s_height = 1.5, p_color = col_text, h_fill = col_bg,
## h_color = col_border, filename="FamAgg_hl.png", p_family = "Aller_Lt")