Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
bird_pipeline_registry
SRP-pipeline
Commits
208c8b30
Commit
208c8b30
authored
Sep 09, 2020
by
Philippe BORDRON
Browse files
reduce the number of columns in legend in order to maximize the plot surface
parent
f27f3ab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
SCRIPTS/DE/qualityControl.R
View file @
208c8b30
...
...
@@ -53,16 +53,17 @@ acp2d<-function(pca, comp=1:2, group=NULL, plotVars = FALSE, pointSize=2, plotTe
percentVar
<-
pca
$
percentVar
functPlot
<-
ifelse
(
plotText
,
geom_text
,
geom_point
)
coor
=
ifelse
(
plotVars
,
"rotation"
,
"x"
)
ngroup
<-
0
if
(
is.null
(
group
)){
d
<-
data.frame
(
PC1
=
pca
[[
coor
]][,
comp
[
1
]],
PC2
=
pca
[[
coor
]][,
comp
[
2
]]);
graph
<-
ggplot
(
data
=
d
,
mapping
=
aes
(
x
=
PC1
,
y
=
PC2
,
label
=
rownames
(
d
)))
}
else
{
d
<-
data.frame
(
PC1
=
pca
[[
coor
]][,
comp
[
1
]],
PC2
=
pca
[[
coor
]][,
comp
[
2
]],
group
=
group
);
graph
<-
ggplot
(
data
=
d
,
mapping
=
aes
(
x
=
PC1
,
y
=
PC2
,
colour
=
group
,
label
=
rownames
(
d
)))
ngroup
<-
length
(
unique
(
group
))
}
legend_text_size
<-
8
legend_text_size
<-
ifelse
(
is.null
(
group
),
legend_text_size
,
max
(
2
,
min
(
legend_text_size
,
round
(
legend_text_size
*
32
/
length
(
unique
(
group
))))
))
default_
legend_text_size
<-
8
legend_text_size
<-
ifelse
(
is.null
(
group
),
default_
legend_text_size
,
max
(
2
,
min
(
default_
legend_text_size
,
round
(
default_
legend_text_size
*
32
/
n
group
))))
theme
<-
theme
(
panel.background
=
element_blank
(),
panel.border
=
element_rect
(
fill
=
NA
),
panel.grid.major
=
element_blank
(),
...
...
@@ -75,7 +76,11 @@ acp2d<-function(pca, comp=1:2, group=NULL, plotVars = FALSE, pointSize=2, plotTe
legend.text
=
element_text
(
size
=
legend_text_size
)
# manage legend text size according to number of conditions
)
graph
<-
graph
+
theme
graph
<-
graph
+
guides
(
colour
=
guide_legend
(
override.aes
=
list
(
size
=
legend_text_size
/
(
2
*
pointSize
))))
# adjust dot size into legend
graph
<-
graph
+
guides
(
col
=
guide_legend
(
ncol
=
ifelse
(
ngroup
==
0
,
NULL
,
ceiling
(
ngroup
/
24
)),
# limit the number of columns to keep the plot large enough; maybe take legend_text_size
override.aes
=
list
(
size
=
legend_text_size
/
(
2
*
pointSize
))
# adjust dot size into legend
))
graph
<-
graph
+
functPlot
(
size
=
pointSize
)
+
xlab
(
paste0
(
"PC"
,
comp
[
1
],
": "
,
round
(
percentVar
[
comp
[
1
]]
*
100
),
"% variance"
))
+
ylab
(
paste0
(
"PC"
,
comp
[
2
],
": "
,
round
(
percentVar
[
comp
[
2
]]
*
100
),
"% variance"
))
...
...
Write
Preview
Markdown
is supported
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