Skip to content

Commit a1d6ad2

Browse files
committed
ggmanZoom_addpoints
1 parent 41db05a commit a1d6ad2

File tree

8 files changed

+175
-4
lines changed

8 files changed

+175
-4
lines changed

.Rhistory

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,104 @@ q()
245245
n
246246
q()
247247
n
248+
head(p2$data)
249+
dfm0 <- p2$data
250+
dfm0
251+
dfm1 <- toy.gwas
252+
library(data.table)
253+
dfm <- toy.gwas
254+
head(dfm0)
255+
dfm <- toy.gwas[1:20]
256+
dfm <- toy.gwas[1:20,]
257+
dfm
258+
snp="snp"
259+
head(toy.gwas)
260+
head(dfm1)
261+
head(dfm0)
262+
head(dfm1)
263+
head(dfm)
264+
dfm <- toy.gwas
265+
head(dfm)
266+
head(dfm1)
267+
dfm
268+
dfm1 <- data.frame(snp="rs1_3595",pvalue=0.80)
269+
dfm1
270+
dfm
271+
head(dfm0)
272+
dim(dfm0)
273+
dfm <- dfm[,c("snp","pvalue")]
274+
dfm
275+
dfm0
276+
dfm
277+
dfm <- dfm0
278+
dfm
279+
dfm$pvalue <- dfm$pvalue-0.1
280+
dfm
281+
dfm[3,2]
282+
dfm[3,3]
283+
dfm[2,3]
284+
dfm[2,3] <- 0.05
285+
dfm
286+
p1
287+
head(dfm0)
288+
p1
289+
dfm
290+
p1
291+
dfm0
292+
head(dfm0)
293+
head(dfm)
294+
ggmanZoomPlot
295+
p1
296+
d1$c
297+
1:10
298+
length(d1)
299+
dim(d1)
300+
d1
301+
d1
302+
d2
303+
p1
304+
head(dfm)
305+
p1
306+
p1
307+
p1
308+
p1
309+
p1
310+
p1
311+
p1
312+
p1
313+
p1
314+
p1
315+
p1
316+
p1
317+
p1
318+
ggave("test.pdf")
319+
ggsave("test.pdf")
320+
system("open test.pdf")
321+
class(ggmanZoomPlot)
322+
color="red"
323+
color.legend.title="Analysis"
324+
color.legend.name="new analysis"
325+
scm
326+
p1
327+
scm
328+
p1
329+
getwd()
330+
q()
331+
n
332+
q()
333+
n
334+
class(ggmanZoomPlot)
335+
a = list(a=1,b=2)
336+
a
337+
a$a
338+
a$b
339+
q()
340+
n
341+
x
342+
(
343+
q()
344+
n
345+
head(tempdfm)
346+
tempdfm
347+
tempdfm
348+
?q

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(ggmanHighlightGroup)
77
export(ggmanLabel)
88
export(ggmanZoom)
99
export(ggmanZoom.old)
10+
export(ggmanZoom_addpoints)
1011
import(ggplot2)
1112
import(ggrepel)
1213
importFrom(gtools,mixedorder)

R/.#ggmanZoom.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
veera@Veeras-MacBook-Pro-2.local.3651

R/genetracks.refseq.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,17 @@ genetracks.refseq <- function(){
124124
ymax = ymax, fill = as.factor(strand)),
125125
alpha = 0.03,inherit.aes = FALSE)
126126
}
127-
p1 + scale_y_continuous(breaks = 0:ymax+1, labels = 0:ymax+1, limits = c(-1-(as.numeric(stack.level)), ymax))
127+
p1 + scale_y_continuous(breaks = 0:ymax+1, labels = 0:ymax+1, limits = c(-1-(as.numeric(stack.level)), ymax))
128+
if(!is.na(point.legend.title)){
129+
scm = c(point.color)
130+
names(scm) = point.legend.name
131+
p1 <- p1 + geom_point(aes(color=point.legend.name))+
132+
scale_color_manual(name=point.legend.title,
133+
values=scm)
134+
}
135+
class(p1) <- append(class(p1),"ggman")
136+
p1 <- list(plot=p1,
137+
point.legend.title=point.legend.title,
138+
scm=scm)
139+
return(p1)
128140
}

R/ggman.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,4 @@ Specify the name of the column with pvalues")
251251
class(p1) <- append(class(p1), "ggman")
252252
return(p1)
253253
}
254-
255254
}

R/ggmanZoom.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#' @param xlabel X axis label
1919
#' @param ylabel Y axis label
2020
#' @param title Plot title
21+
#' @param point.legend.title point legend title
22+
#' @param point.legend.name point legend name
2123
#' @param ... other arguments to pass to \code{\link{geom_point}}
2224
#' @return A regional association plot
2325
#'
@@ -54,6 +56,9 @@ ggmanZoom <- function(
5456
xlabel = NA,
5557
ylabel = NA,
5658
title = NA,
59+
point.legend.title=NA,
60+
point.legend.name=NA,
61+
point.color="black",
5762
...
5863
){
5964
##check inputs
@@ -83,13 +88,17 @@ ggmanZoom <- function(
8388
}
8489

8590
p1 <- ggplot(dfm.sub, aes(bp,marker)) + geom_point(...) +
86-
labs(x = xlabel, y = ylabel, title = title)
87-
91+
labs(x = xlabel, y = ylabel, title = title)
8892
if(gene.tracks){
8993
##refseq
9094
environment(genetracks.refseq) <- environment()
9195
genetracks.refseq()
9296
} else {
97+
scm = c(point.color)
98+
names(scm) = point.legend.name
99+
p1 <- list(plot=p1,
100+
scm.title = point.legend.title,
101+
scm = scm)
93102
return(p1)
94103
}
95104
}

R/ggmanZoom_addpoints.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#' ggmanZoom_addpoints
2+
#'
3+
#' Zoom in to a specific region of the Manhattan Plot
4+
#'
5+
#' @param ggmanPlot A ggplot object of class 'ggman'
6+
#' @param chromosome Chromosome identifier
7+
#' @param start.position Starting basepair position
8+
#' @param end.position Ending basepair position
9+
#' @param ... other arguments to pass to \code{\link{geom_point}}
10+
#' @return A regional association plot
11+
#'
12+
#' @examples
13+
#'
14+
#'
15+
#'
16+
#'
17+
#'
18+
#'
19+
#' @export
20+
ggmanZoom_addpoints <- function(ggmanZoomPlot,
21+
dfm,
22+
snp="SNP",
23+
pvalue="P",
24+
point.color = "red",
25+
point.legend.name="new analysis",
26+
...){
27+
ggmanZoomPlot1 <- ggmanZoomPlot[[1]]
28+
dfm0 <- ggmanZoomPlot1$data
29+
dfm <- as.data.frame(dfm)
30+
dfm1 <- data.frame(snp = dfm[,snp],pvalue=dfm[,"pvalue"])
31+
dfm <- merge(dfm0[,c("snp","index","bp")],dfm1,by="snp")
32+
dfm$marker <- -log10(dfm$pvalue)
33+
scmnames <- c(names(ggmanZoomPlot$scm),point.legend.name)
34+
scm <- c(ggmanZoomPlot$scm,point.color)
35+
names(scm) <- scmnames
36+
point.legend.title <- ggmanZoomPlot$point.legend.title
37+
p1 <- ggmanZoomPlot1 +
38+
geom_point(data=dfm,aes(color=point.legend.name), shape=5)+
39+
scale_color_manual(name=point.legend.title,
40+
values=scm)
41+
class(p1) <- append(class(p1), "ggman")
42+
p1 <- list(plot=p1,
43+
scm=scm,
44+
point.legend.title=point.legend.title)
45+
return(p1)
46+
47+
48+
}

test.pdf

6.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)