Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
khalid
radsex
Commits
dc3a59ff
Commit
dc3a59ff
authored
Sep 11, 2017
by
Romain Feron
Browse files
Fixed a scale bug in heatmap R script - now all plots will have the same full color scale
parent
fc96e206
Changes
1
Hide whitespace changes
Inline
Side-by-side
radseq_analysis/visualization/r_scripts/heatmap.R
View file @
dc3a59ff
...
...
@@ -27,9 +27,10 @@ sex_heatmap = function(file_path, species_name="none"){
data
=
suppressMessages
(
read_delim
(
file_path
,
"\t"
,
escape_double
=
FALSE
,
col_names
=
FALSE
,
trim_ws
=
TRUE
))
bins
=
c
(
0
,
1
,
2
,
5
,
25
,
100
,
1000
)
bin_labels
=
c
(
'0'
,
'1'
,
'2
-4
'
,
'5-24'
,
'25-99'
,
'100-999'
,
'>1000'
)
bin_labels
=
c
(
'0'
,
'1'
,
'2'
,
'5-24'
,
'25-99'
,
'100-999'
,
'>1000'
)
get_palette
=
colorRampPalette
(
c
(
"white"
,
"navyblue"
))
palette
=
get_palette
(
length
(
bins
))
palette
=
get_palette
(
length
(
bin_labels
))
names
(
palette
)
=
bins
males
=
rep
(
seq
(
0
,
dim
(
data
)[
2
]
-
1
),
dim
(
data
)[
1
])
females
=
c
()
...
...
@@ -42,13 +43,13 @@ sex_heatmap = function(file_path, species_name="none"){
}
d
=
data.frame
(
'Males'
=
males
,
'Females'
=
females
,
'Loci'
=
loci
)
d
$
Loci
=
d
$
Loci
+
1
d
$
Loci
=
d
$
Loci
group
=
c
()
for
(
i
in
1
:
dim
(
d
)[
1
])
{
group
=
c
(
group
,
bins
[
tail
(
which
(
d
$
Loci
[
i
]
>=
bins
),
n
=
1
)])
}
d
$
Bin
=
factor
(
group
)
d
$
Bin
=
factor
(
group
,
levels
=
bins
)
title
=
""
if
(
species_name
!=
"none"
)
{
...
...
@@ -58,13 +59,14 @@ sex_heatmap = function(file_path, species_name="none"){
g
=
ggplot
(
d
,
aes
(
x
=
Males
,
y
=
Females
))
+
geom_tile
(
aes
(
fill
=
Bin
),
color
=
"grey"
)
+
ggtitle
(
title
)
+
theme
(
plot.title
=
element_text
(
hjust
=
0.5
))
+
scale_fill_manual
(
name
=
"Number of\nhaplotypes"
,
values
=
palette
,
labels
=
bin_labels
)
+
scale_fill_manual
(
name
=
"Number of\nhaplotypes"
,
breaks
=
bins
,
values
=
palette
,
labels
=
bin_labels
,
drop
=
FALSE
)
+
scale_x_continuous
(
breaks
=
seq
(
0
,
max
(
d
$
Males
),
5
),
minor_breaks
=
seq
(
0
,
max
(
d
$
Males
),
1
))
+
scale_y_continuous
(
breaks
=
seq
(
0
,
max
(
d
$
Females
),
5
),
minor_breaks
=
seq
(
0
,
max
(
d
$
Females
),
1
))
return
(
g
)
}
heatmap
=
sex_heatmap
(
input_file_path
,
species_name
)
n_males
=
max
(
ggplot_build
(
heatmap
)
$
data
[[
1
]]
$
x
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment