Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cAmpSeqR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simeon Rossmann
cAmpSeqR
Commits
bbaf3a7c
Commit
bbaf3a7c
authored
1 year ago
by
Simeon
Browse files
Options
Downloads
Patches
Plain Diff
new functions
parent
f111274c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/plot_cluster_thresholds.R
+51
-0
51 additions, 0 deletions
R/plot_cluster_thresholds.R
R/str_pad_to_max.R
+18
-0
18 additions, 0 deletions
R/str_pad_to_max.R
with
69 additions
and
0 deletions
R/plot_cluster_thresholds.R
0 → 100644
+
51
−
0
View file @
bbaf3a7c
#' Plot cluster counts across similarity thresholds
#'
#' This function creates a plot of cluster thresholds based on a given table of cluster counts
#' and a defined plateau.
#'
#' @param clus_counts_tbl A data frame containing the cluster counts. It should have two columns:
#' - threshold: The threshold values.
#' - cluster_number: The corresponding number of clusters.
#'
#' @param plateaus A named numeric vector containing the plateau information. It should have the following
#' elements:
#' - plateau_start: The starting threshold value of the plateau.
#' - plateau_end: The ending threshold value of the plateau.
#' - cluster_number: The number of clusters within the plateau.
#'
#' @return A plot of cluster thresholds with highlighted plateaus.
#'
#' @examples
#' clus_counts_tbl <- data.frame(
#' threshold = c(0.1, 0.2, 0.3, 0.4, 0.5),
#' cluster_number = c(7, 6, 6, 5, 4)
#' )
#'
#' plateaus <- c(
#' plateau_start = 0.2,
#' plateau_end = 0.3,
#' cluster_number = 6
#' )
#'
#' plot_cluster_thresholds(clus_counts_tbl, plateaus)
#'
#'
#' @export
plot_cluster_thresholds
<-
function
(
clus_counts_tbl
,
plateaus
)
{
ggplot
(
clus_counts_tbl
,
aes
(
x
=
threshold
,
y
=
cluster_number
))
+
geom_rect
(
aes
(
xmin
=
plateaus
[
'plateau_start'
],
xmax
=
plateaus
[
'plateau_end'
],
ymin
=
0
,
ymax
=
max
(
cluster_number
)),
fill
=
'lightblue'
)
+
geom_point
()
+
annotate
(
'text'
,
x
=
plateaus
[
'plateau_start'
],
y
=
max
(
clus_counts_tbl
$
cluster_number
)
/
2
,
label
=
paste
(
'Clusters:'
,
plateaus
[
'cluster_number'
]),
hjust
=
0
)
+
annotate
(
'text'
,
x
=
plateaus
[
'plateau_start'
],
y
=
max
(
clus_counts_tbl
$
cluster_number
)
/
2.5
,
label
=
paste
(
'Threshold:'
,
plateaus
[
'plateau_start'
],
'to'
,
plateaus
[
'plateau_end'
]),
hjust
=
0
)
}
This diff is collapsed.
Click to expand it.
R/str_pad_to_max.R
0 → 100644
+
18
−
0
View file @
bbaf3a7c
#' Pad string to longest length
#'
#' Pads each element in a character vector to the length of the longest element in the vector.
#'
#' @param vec The character vector to be padded.
#' @param ... Additional arguments to be passed to `str_pad`.
#'
#' @return The character vector with each element padded to the maximum length.
#'
#' @examples
#' str_pad_to_max(c("hello", "world", "foo", "bar", "x"))
#'
#' @importFrom stringr str_pad str_length
#'
#' @export
str_pad_to_max
<-
function
(
vec
=
c
(),
...
){
str_pad
(
vec
,
max
(
str_length
(
vec
)),
...
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment