Compare commits

..

33 Commits

Author SHA1 Message Date
marcelcosta c88359c801 Specify package for "filter" function 2025-04-15 11:38:56 +02:00
marcelcosta a9bff2e058 Update 'R/ggstats_add_xy.R'
change !!!sym_link for .data[[exclude_group]].
2025-03-27 15:06:00 +01:00
marcelcosta 217bca2480 Correct for more than 1 facet. 2025-03-06 13:46:43 +01:00
marcelcosta ab96f5ec6a .data pronoun only allows one facet variable. I have changed into !!!syms(). 2025-03-06 13:12:00 +01:00
marcelcosta d42e4ff6f3 Change error stat.test for table_stat 2025-03-05 14:54:15 +01:00
marcelcosta 9ef27ea7de Add dodge option to ggstats_add_xy 2024-10-25 15:06:19 +02:00
marcelcosta a4483c84e6 Adding md2csv and tab2md functions. 2024-10-11 10:42:29 +02:00
marcelcosta 0cb487caa4 Correcting bugs. 2023-02-07 11:49:16 +01:00
marcelcosta c1bd92a7c9 Corregir bug, en cada panel salía misma y. 2023-01-24 15:06:15 +01:00
marcelcosta cde38f8aa6 Corregir nombre de función. 2023-01-24 14:31:13 +01:00
marcelcosta 296d98706a Corregir ejemplo. 2023-01-24 14:19:24 +01:00
marcelcosta ed125951a8 Cambiar orden parámetros. 2023-01-24 14:18:59 +01:00
marcelcosta 389b97d3b4 Adaptada la función para permitir comparaciones entre elementos de la x, no sólo agrupados. 2023-01-24 14:17:22 +01:00
marcelcosta de89c5258d Corregir error group->xcol 2023-01-24 12:58:23 +01:00
marcelcosta f44ec4b7fe Update 'DESCRIPTION' 2022-09-01 17:10:08 +02:00
marcelcosta d4521b874c Update 'DESCRIPTION' 2022-09-01 17:09:00 +02:00
Costa 9ab832c900 Solución de algún bug con el ordenamiento de elementos == 1. 2022-03-24 12:32:48 +01:00
Costa e57141aa22 Hacer que cuando haya un eje que sólo tenga un elemento ordene el otro. 2022-03-24 12:17:32 +01:00
Costa bd98a08c31 Hacer que no ordene si una de las dimensiones no tiene más de un elemento para que no de error en el hclust. 2022-03-24 12:08:43 +01:00
Costa fb62bdf49d Añadidos los \ que se habían perdido. 2022-03-22 16:52:52 +01:00
Costa 4445b00037 Cambio de orden. 2022-03-22 16:40:56 +01:00
Costa 7025db93b6 Corregido la ausencia del } al final. 2022-02-24 15:51:54 +01:00
Costa 7a9b49f859 Añadiendo las modificaciones para que haga el facet correctamente. 2022-02-24 15:49:19 +01:00
Costa 3c77771ccb Corregido error en ejemplo. 2022-02-24 15:48:33 +01:00
Costa 8fe1c77f74 Adaptado para incluir Facets. 2022-02-24 15:28:36 +01:00
Costa 9fe57a3f32 Añadida función ggstats_add_xy 2022-02-15 11:46:13 +01:00
marcelcosta 9c9d5e3a52 He añadido gglegend, sem y perc a la vignette. 2022-02-12 12:23:08 +01:00
marcelcosta 46b6efc706 Añadida función sem. 2022-02-12 12:05:34 +01:00
marcelcosta 728b2429f6 Añadida función gglegend. 2022-02-12 12:05:15 +01:00
marcelcosta 31811bec30 Añadida función perc. 2022-02-12 12:05:04 +01:00
marcelcosta 05da9ac572 Añadida explicación sobre añadir color al ggheatmap. 2022-02-12 11:33:58 +01:00
marcelcosta d49b1b2226 Merge branch 'main' of https://git.ratg.cat/marcelcosta/CitFuns into main 2022-02-12 10:42:10 +01:00
marcelcosta 058115e4a8 Añadiendo archivo README.md 2022-02-12 10:41:34 +01:00
16 changed files with 408 additions and 2 deletions
+2 -1
View File
@@ -7,5 +7,6 @@ Maintainer: Marcel Costa <marcelcosta@mcosta.cat>
Description: Funciones internas para el laboratorio CIT Description: Funciones internas para el laboratorio CIT
License: GPL License: GPL
Encoding: UTF-8 Encoding: UTF-8
Suggests: rmarkdown
VignetteBuilder: knitr
LazyData: true LazyData: true
VignetteBuilder: knitr
+27 -1
View File
@@ -16,7 +16,33 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro
if (grouping == "median"){ if (grouping == "median"){
df<-df %>% summarise(Value=median(Value)) %>% ungroup df<-df %>% summarise(Value=median(Value)) %>% ungroup
} }
order<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame)
if (length(unique(df$VarX)) > 1 & length(unique(df$VarY)) >
1) {
order <- clustsort(df %>% spread(VarY, Value) %>% select(!all_of(exclude_group)) %>%
as.data.frame)
}
else {
order <- list()
if (length(unique(df$VarX)) > 1) {
xhclust <- df %>% spread(VarY, Value) %>%
select(!all_of(exclude_group)) %>% as.data.frame
order[["x"]] <- pull(xhclust, 1)[hclust(dist(xhclust %>%
select(-1)))$order]
}
else {
order[["x"]] <- df %>% pull(VarX) %>% unique
}
if (length(unique(df$VarY)) > 1) {
yhclust <- clustsort(df %>% spread(VarY, Value) %>%
select(!all_of(exclude_group)) %>% as.data.frame)
order[["y"]] <- colnames(yhclust)[2:ncol(yhclust)][hclust(dist(t(yhclust %>%
select(-1))))$order]
}
else {
order[["y"]] <- df %>% pull(VarY) %>% unique
}
}
if (scale != "none"){ if (scale != "none"){
if (scale == "rows"){ if (scale == "rows"){
+13
View File
@@ -0,0 +1,13 @@
gglegend<-function(data, x, y, var, stat="median", color="black", ...){
if (stat == "median"){
data<-data %>% group_by({{var}}) %>% summarise("{{x}}":=median({{x}}, na.rm=T), "{{y}}":=median({{y}}, na.rm=T))
}
if (stat == "mean"){
data<-data %>% group_by({{var}}) %>% summarise("{{x}}":=mean({{x}}, na.rm=T), "{{y}}":=mean({{y}}, na.rm=T))
}
if (!is.null(color)){
return(geom_label(data = data, aes({{x}},{{y}}, label={{var}}), color=color, ...))
}else{
return(geom_label(data = data, aes({{x}},{{y}}, label={{var}}),...))
}
}
+82
View File
@@ -0,0 +1,82 @@
ggstats_add_xy<-function(table_stat, table, xcol=NULL, group, y="max", bracket.offset=0.05, bracket.inspace=0.05, exclude_group=NULL, dodge=0.75){
## Adapted version to fit rstatix output
value.var<-table_stat[[1,".y."]]
if (is.null(xcol)){
x<-colnames(table_stat)[1]
}else{x<-xcol}
if(!is.null(group)){table[,group]<-as.factor(pull(table,group))}
table[,x]<-as.factor(pull(table,x))
if (is.null(exclude_group)){
table_agg<-table %>% group_by(.data[[x]])
}else{
table_agg<-table %>% group_by(.data[[x]], !!!syms(exclude_group))
}
if (y == "max"){
agg<-table_agg %>% summarise(max=max(.data[[value.var]], na.rm = T))
if(!is.null(exclude_group)){agg<-table_agg %>% group_by(!!!syms(exclude_group)) %>% summarise(max=max(.data[[value.var]], na.rm=T))}
}else if (y == "mean"){
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)) %>% spread(group, mean)
agg<- data.frame(x=agg[,1], "max"=apply(agg[,2:ncol(agg)], 1, max, na.rm=T))
colnames(agg)[1]<-x
}else if (y == "mean+sd"){
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)+sd(.[[value.var]], na.rm=T)) %>% spread(group, mean)
agg<- data.frame(x=agg[,1], "max"=apply(agg[,2:ncol(agg)], 1, max, na.rm=T))
colnames(agg)[1]<-x
}else if (y == "mean+sem"){
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)+sem(.[[value.var]], na.rm=T)) %>% spread(group, mean)
agg<- data.frame(x=agg[,1], "max"=apply(agg[,2:ncol(agg)], 1, max, na.rm=T))
colnames(agg)[1]<-x
}
group.list<-list()
count<-1
if(!is.null(group)){table_stat<-mutate(table_stat, {{x}}:=as.factor(.data[[x]]))}
for (i in 1:nrow(table_stat)){
group.list[[count]]<-c(table_stat %>% slice(i) %>% pull(group1),table_stat%>% slice(i) %>% pull(group2))
count<-count+1
}
if(!is.null(group)){
x.index<-sapply(table_stat %>% pull(x), function(y) which(levels(table_stat %>% pull(x)) == y))
t<-tibble("y.position"=merge(table_stat, agg ,sort=F)[,"max"]+diff(range(table[value.var], na.rm = T))*bracket.offset,
"groups"=group.list,
"x.temp"=x.index,
"xmin"=(match(table_stat %>% pull(x), levels(table[,x]))+dodge*((match(table_stat$group1, levels(table[,group]))-0.5)/length(levels(table[,group]))-0.5)),
"xmax"=match(table_stat %>% pull(x), unique(table[,x]))+dodge*((match(table_stat$group2, levels(table[,group]))-0.5)/length(levels(table[,group]))-0.5)
) %>% rename("x"="x.temp")
}else{
t<-tibble("y.position"=merge(table_stat, agg ,sort=F)[,"max"]+diff(range(table[value.var], na.rm = T))*bracket.offset,
"groups"=group.list,
# "x.temp"=x.index,
)# %>% rename("x"="x.temp")
}
if (!is.null(group)){
if (!is.null(exclude_group)){
for (j in unique(pull(table_stat, all_of(exclude_group)))){
for (dia in unique(pull(table_stat,all_of(xcol)))){
if (table_stat %>% dplyr::filter(p < 0.05) %>% dplyr::filter(.data[[x]] == dia & .data[[exclude_group]] == j) %>% nrow() > 0){
t[table_stat[,x] == dia & table_stat[,exclude_group] == j,"y.position"]<-seq(t[table_stat[,x] == dia & table_stat[,exclude_group] == j,"y.position"][[1,1]],
t[table_stat[,x] == dia & table_stat[,exclude_group] == j,"y.position"][[1,1]]+diff(range(table[,value.var], na.rm = T))*bracket.inspace*(nrow(table_stat[table_stat[,x] == dia & table_stat[,exclude_group] == j,])-1),
by=diff(range(table[,value.var], na.rm = T))*bracket.inspace)
}
}
}
}else{
for (dia in unique(pull(table_stat,all_of(xcol)))){
t[table_stat[,x] == dia,"y.position"]<-seq(t[table_stat[,x] == dia,"y.position"][[1,1]],
t[table_stat[,x] == dia,"y.position"][[1,1]]+diff(range(table[,value.var], na.rm = T))*bracket.inspace*(nrow(table_stat[table_stat[,x] == dia,])-1),
by=diff(range(table[,value.var], na.rm = T))*bracket.inspace)
}
}
}else{
for (dia in unique(pull(mutate(table_stat,dia=paste0(!!!syms(exclude_group))),dia))){
t[apply(table_stat[,exclude_group], 1, paste, collapse="") == dia, "y.position"]<-seq(t[apply(table_stat[,exclude_group], 1, paste, collapse="") == dia,"y.position"][[1,1]],
t[apply(table_stat[,exclude_group], 1, paste, collapse="") == dia,"y.position"][[1,1]]+
diff(range(table[,value.var], na.rm = T))*
bracket.inspace*(nrow(table_stat[apply(table_stat[,exclude_group], 1, paste, collapse="") == dia,])-1),
by=diff(range(table[,value.var], na.rm = T))*bracket.inspace)
}
}
return(cbind(table_stat,t) %>% as_tibble)
}
+7
View File
@@ -0,0 +1,7 @@
md2csv<-function(text, rm_blank=T){
text<-strsplit(text, "\n")[[1]]
text<-gsub("^[ |]*|[|][ ]*$","",text)
if(rm_blank){text<-gsub(" ","",text)}
text<-gsub("[|]",",",text)
return(cat(text,sep = "\n"))
}
+7
View File
@@ -0,0 +1,7 @@
perc<-function(x, per100=T){
if (per100==T){
return(x*100/sum(x, na.rm = T))
}else{
return(x/sum(x, na.rm = T))
}
}
+4
View File
@@ -0,0 +1,4 @@
sem <- function(x, na.rm=F){
sem<-sd(x, na.rm = na.rm)/sqrt(length(x))
return(sem)
}
+10
View File
@@ -0,0 +1,10 @@
tab2md<-function(table){
samples_csv<-table
table<-apply(table, 1, paste, collapse="|")
table<-gsub("^","|",table)
table<-gsub("$","|",table)
table<-c(paste0("|",paste(colnames(samples_csv), collapse="|"),"|"),
paste0("|",paste(rep("---",ncol(samples_csv)), collapse="|"),"|"),
table)
cat(table, sep="\n")
}
+26
View File
@@ -0,0 +1,26 @@
# CitFuns
Este repositorio contiene un paquete de R que recopila diferentes funciones útiles para el laboratorio CIT del ICO, en Barcelona, aunque puede ser útil para cualquiera que haga análisis parecidos.
Para instalar el paquete se necesita tener instalado:
- [Rtools](https://cran.r-project.org/bin/windows/Rtools/rtools40.html)
- [Git](https://git-scm.com/downloads)
Y las funciones dependen de los paquetes:
- tidyverse
- Hmisc
- gtools
Una vez cuplidas las dependencias, el paquete se instala así:
```r
devtools::install_git("https://git.ratg.cat/marcelcosta/CitFuns.git", build_vignettes=T)
```
Puedes consultar la documentación ejecutando:
```r
browseVignettes("CitFuns")
```
+43
View File
@@ -0,0 +1,43 @@
\name{gglegend}
\alias{gglegend}
\title{gglegend}
\usage{
gglegend(data, x, y, var, stat="median", color="black", ...)
}
\arguments{
\item{data}{A data frame from where to take x and y axis, and the grouping variable.}
\item{x}{The variable that will be used for X axis in the heatmap.}
\item{y}{The variable that will be used for Y axis in the heatmap.}
\item{value}{The variable that will be used for grouping the heatmap. The labels will be taken from it}
\item{stat}{The statistical central test that will be used to calculate the label coordinates. "mean" or "median" are posible, defaulting to "median".}
\item{color}{The color of the labels, "black" by default. If NULL, nothig will be passed to the geom_label so it may be taken from aesthetics.}
\item{...}{Other arguments that will be passed to the geom_label function.}
}
\description{
Generates a geom_label object with labels in the center of each population or agrupation.
}
\examples{
library(tidyverse)
library(Rtsne)
library(Rphenograph)
library(igraph)
## We will generate an example using tSNE and Phenograph algorithms, but can be applied to any other situation.
iris_unique <- unique(iris) # Remove duplicates
iris_matrix <- as.matrix(iris_unique[,1:4])
# Set a seed if you want reproducible results
set.seed(42)
tsne_out <- Rtsne(iris_matrix,pca=FALSE,perplexity=30,theta=0.0) # Run TSNE
rpheno<-Rphenograph(tsne_out$Y)
df<-data.frame(as.data.frame(tsne_out$Y), "Clust"=factor(membership(rpheno[[2]])))
head(df)
ggplot(df, aes(V1,V2, color=Clust))+
geom_point()+
gglegend(df, V1, V2, Clust)+
guides(color="none")
}
+37
View File
@@ -0,0 +1,37 @@
\name{ggstats_add_xy}
\alias{ggstats_add_xy}
\title{ggstats_add_xy}
\usage{
ggstats_add_xy(table_stat, table, group, xcol=NULL, y="max", bracket.offset=0.05, bracket.inspace=0.05, exclude_group=NULL, dodge=0.75)
}
\arguments{
\item{table_stat}{A table generated by a rstatix funcion such as t_test() or wilcox_test().}
\item{table}{The original table that was introduced to ggplot.}
\item{xcol}{The X-axis variable. If null (the default), the function will pick the first column. This is intended when exclude_group is null.}
\item{group}{The grouping variable. If null, the function will emulate the add_y_position function instead of add_xy_position.}
\item{y}{The algorithm used to calculate the y height. Is useful to adapt to plots that show all events, bars with the mean, etc... Options are "max" (default), "mean", "mean+sd", "mean+sem".}
\item{bracket.offset}{Increasing this parameter incresases the y position of the brackets.}
\item{bracket.inspace}{Increasing this parameter increases the space between brackets.}
\item{exclude_group}{Variable(s) that will not be grouped. This aims to preserve the variable in order to facet.}
\item{dodge}{How much dodge to perform (different ggplot geoms have different dodge values).}
}
\description{
Generates a table with the coordinates that is required by the ggpubr function "stat_pvalue_manual".
}
\examples{
library(tidyverse)
library(ggpubr)
library(rstatix)
df<-data.frame("pats"=paste0("PAT", 1:20), "Group"=rep(c("A","B"),each=10),"CytA"=rnorm(20,5), "CytB"=rnorm(20,5),"CytC"=c(rnorm(5,10),rnorm(5,10),rnorm(5,5),rnorm(5,5)),"CytD"=rnorm(20,5),"CytE"=c(rnorm(5,10),rnorm(5,5),rnorm(5,10),rnorm(5,5)),"CytF"=rnorm(20,5),"CytG"=c(rnorm(5,5),rnorm(5,5),rnorm(5,7),rnorm(5,7)))
mdf<-gather(df, "Cytokine","Value",-c(pats,Group))
g<-ggplot(mdf, aes(Cytokine, Value, color=Group))+
geom_boxplot()+
geom_point(position=position_dodge(width = 0.75))
stat.test<-mdf \%>\% group_by(Cytokine) \%>\% t_test(Value~Group)
g+stat_pvalue_manual(ggstats_add_xy(stat.test, mdf, "Cytokine","Group"), label = "p", tip.length = 0.02, hide.ns = T)
}
+28
View File
@@ -0,0 +1,28 @@
\name{md2csv}
\alias{md2csv}
\title{md2csv}
\usage{
md2csv(text, rm_blank =T)
}
\arguments{
\item{text}{An md text that you want to convert to csv. Note that you must eliminate the line that separates title from the rest.}
\item{text}{Bolean to specify if you want to remove spaces or not.}
}
\description{
This function converts an Markdown (md) table into csv format.
}
\examples{
text<-"|Letter|Number|
|A| 1|
|B| 2|
|C| 3|
|D| 4|
|E| 5|
|F| 6|
|G| 7|
|H| 8|
|I| 9|
|J|10|"
md2csv(text)
}
+25
View File
@@ -0,0 +1,25 @@
\name{perc}
\alias{perc}
\title{perc}
\usage{
perc(x, per100=T)
}
\arguments{
\item{x}{A numeric vector or an R object but not a factor coercible to numeric by as.double(x).}
\item{perc}{A logical value indicating whether the result must sum 100 (TRUE) or 1 (FALSE).}
}
\description{
This function the percentages of a numeric vector.
}
\examples{
v<-c(2,5,10,3)
perc(v)
# It can be used with dplyr tables
library(tidyverse)
df<-data.frame("X"=c("A","A","B","B"), "Y"=v)
df \%>\% mutate(Y=perc(Y))
# Or it can be under 1
df \%>\% mutate(Y=perc(Y, per100=F))
}
+17
View File
@@ -0,0 +1,17 @@
\name{sem}
\alias{sem}
\title{sem}
\usage{
sem(x, na.rm=T)
}
\arguments{
\item{x}{A numeric vector or an R object but not a factor coercible to numeric by as.double(x).}
\item{na.rm}{A logical value indicating whether NA values should be stripped before the computation proceeds.}
}
\description{
This function computes the Standard Error of the Mean of the values in x. If na.rm is TRUE then missing values are removed before computation proceeds.
}
\examples{
v<-rnorm(10)
sem(v)
}
+17
View File
@@ -0,0 +1,17 @@
\name{tab2md}
\alias{tab2md}
\title{tab2md}
\usage{
tab2md(text)
}
\arguments{
\item{text}{A data.frame that you want to convert to Markdown.}
}
\description{
This function converts a data.frame into Markdown (md) format.
}
\examples{
table<-data.frame("Letter"=LETTERS[1:10], "Number"=1:10)
tab2md(table)
}
+63
View File
@@ -88,6 +88,11 @@ By default, *other variables not used are eliminated* during the grouping proces
ggheatmap(df, exclude_group = "Met")+facet_grid(.~Met, scales = "free") ggheatmap(df, exclude_group = "Met")+facet_grid(.~Met, scales = "free")
``` ```
You can specify a color instead of being transparent to the tiles:
```{r, fig.width=8}
ggheatmap(df, color="black")
```
Finally, you can scale the heatmap either by rows or by columns: Finally, you can scale the heatmap either by rows or by columns:
```{r, fig.width=8} ```{r, fig.width=8}
@@ -135,3 +140,61 @@ Finally, you can show only the upper part or the lower part of the specular matr
```{r, fig.width=5, fig.height=4} ```{r, fig.width=5, fig.height=4}
ggcorrplot(df, var = "Cyt", value = "Value", color = "black", tri="lower") ggcorrplot(df, var = "Cyt", value = "Value", color = "black", tri="lower")
``` ```
## gglegend
gglegend generates a geom_label that calculates the median or mean coordinate from a group in a dotplot with two numerical axis. This is specially designed for results from tSNE+Phenograph cytometry analysis or scRNAseq analysis.
Lets use some coordinates generated from tSNE and Phenograph alghorithms.
```{r, collapse=TRUE}
v1<-c("12.2003375696557","9.61179669498037","9.71523107560819","9.36085913975228","12.4250267807441","14.3028296270378","10.1352873281603","11.5029598315655","8.56811495574298","10.0823452299921","13.6266459325397","10.9933175551642","9.33699055226273","8.4753653954153","14.8718666962033","15.2360998395043","14.2924029287808","12.3444533761381","14.2993507234786","13.4864775273824","12.7460734690735","13.161500730014","10.1359520632972","12.2185983825899","11.2616934436752","9.90490138562409","11.9609343515576","12.5884534548523","12.0364418615964","10.1870261767374","10.0422315951637","12.7783195658305","14.5992551781486","14.9493239728631","10.158835739269","10.6054386317344","13.2848626188882","11.936894948252","8.7128504500476","11.7737895359261","11.8983735877432","8.02689567143797","9.12243498461827","12.6527770922061","13.9105401986929","9.35741259585257","13.5911333739262","9.58527361989105","13.4456024538875","11.0895916895462","-5.85077686923467","-4.52715357511742","-6.29563605082642","0.575879987115163","-5.00038311800316","-1.78476165367942","-4.78291504182624","2.14145872648519","-4.95470848078674","0.527964928988151","2.0407874996449","-2.01707703338718","0.295902773532714","-4.00219087667774","0.646856668064106","-4.88234548321471","-2.03349635088723","-0.49193567263671","-2.79335406976441","0.448763877743354","-4.75643812997927","-1.42563453004395","-6.23450075793563","-3.62615912431353","-3.76809728669077","-4.60208220139584","-5.85501795453493","-7.05239199090951","-3.20043054503014","1.15876766287925","0.895292755360344","1.14444064679356","-0.176884624041849","-6.35832840326582","-1.65398473342688","-3.79355073906942","-5.5958811065813","-2.73187337265253","-0.874422976991474","0.261500351579398","-0.561805573681923","-3.75892543868909","-0.236866399218848","2.09008746058036","-0.548227337920367","-1.21516952408529","-1.17389146089581","-2.97942173316255","2.22364389707379","-0.740849099358617","-11.53883548612","-6.10528935020874","-12.060454035126","-9.30052482902171","-10.8000103031182","-13.5180286021874","-0.350552508950501","-12.8614336490877","-10.5151593701859","-12.7997253357382","-8.9616405672664","-8.4882832838348","-10.5542279802031","-6.07143684739709","-6.38549255444235","-10.0449160880572","-9.44413278886994","-13.777705761209","-13.7964826297576","-6.8363880475111","-11.5388213442119","-5.6282354747176","-13.6138636099046","-6.381104642862","-11.1812519418261","-12.3831679874129","-5.77325698424297","-5.48616485259332","-9.96244295723046","-12.114107326341","-12.7616465926232","-13.7599167738886","-10.1159812826476","-6.62864900674468","-8.06745259542743","-13.1987304489436","-10.8870376481335","-9.36038405695135","-5.13930391264302","-10.5111656232542","-10.9829759447952","-9.82553470541781","-11.7458951813431","-11.4450763813922","-9.87343759006578","-6.95726085424341","-9.03829069857169","-10.4246847556504","-5.70838830660222")
v2<-c("21.0246799882543","21.1604668637415","22.3065974726199","22.167058907011","21.485793337356","21.034495141115","22.8527942337251","21.4484506937578","22.2141672875484","21.345153106709","20.4880451876175","22.2111273969088","21.4727323576141","22.8241608452394","20.0044199930559","20.4988095357755","20.5599765528411","21.1969434679012","20.0020746075624","21.4337624510195","19.9736219509137","21.5709896392616","23.6577471746758","22.5535814744334","22.8384868736052","20.8650810158446","22.1613883712501","20.7983446457222","20.5655252200496","22.2090780986936","21.7806687207636","20.1194553082707","21.3069459537366","20.662407531373","21.4251709330106","20.765690762975","19.8859038873819","21.7056631952668","22.5041194163155","20.9642232055426","21.3422306162038","21.6367978620734","22.9262096626072","22.4646597147181","22.1141613861558","21.5054873462004","21.4889032804239","22.5008054544748","20.76786026091","21.2016450580895","-8.72858183844766","-9.95487383065406","-9.0344478298343","-10.2479477494554","-9.75424269139439","-11.3104503130975","-10.6530974583924","-10.84576176497","-9.3121096499565","-11.3954821057958","-10.459830426721","-10.7685510257121","-9.6028748910031","-10.8250931981046","-11.4576048366608","-8.99623858309278","-11.6991335601257","-10.3000992136515","-8.80499949660716","-10.5287181221244","-12.1008107052572","-10.0265692008998","-10.9708704570088","-10.5302978352576","-9.54786020396403","-9.23397400708739","-9.24386152038901","-9.65261439968974","-10.9281368746817","-10.9473794707607","-10.4850238433817","-10.4882084917208","-10.4990514736718","-12.0128979043322","-11.941610711928","-11.6458333185284","-9.24844012046275","-8.88646414055994","-11.3227097840251","-10.8268151538455","-11.5279408155446","-10.7575990470602","-10.360283532249","-10.7913818861931","-11.091926796243","-11.0159937813687","-10.982258258046","-10.0920126917865","-10.9583452116076","-10.8108899751332","-9.56368334300102","-12.8367178840931","-11.3709591119047","-11.652506805406","-11.1169982547012","-11.6968611726564","-8.86077529188209","-11.9662163203006","-12.2158702454966","-10.5422338216268","-10.1439305299441","-11.3349056863203","-10.8133385736638","-13.1632816376455","-13.5059352283161","-9.88618491633494","-11.2477309742765","-10.9615658268355","-12.0131549369708","-12.187081729914","-10.6769895449992","-13.1713800408861","-11.9147981603324","-11.3127268327162","-10.6744434631015","-11.6870047899695","-11.4368856559989","-11.7991750334205","-11.4332997824959","-12.0583096122799","-11.9469443936353","-10.9598799506617","-11.3275484766061","-11.0525813106846","-12.3015921365232","-11.4579022030789","-9.5065760211426","-11.203396001218","-11.9253283065003","-10.5294239353879","-10.3400935752971","-9.87954083672559","-10.6401156456368","-10.0740874914124","-10.1578866019443","-11.5501223255682","-10.5308167593782","-9.35047777292819","-12.4071042980126")
clust<-c("1","2","2","2","1","1","2","1","2","2","1","2","2","2","1","1","1","1","1","1","1","1","2","1","2","2","1","1","1","2","2","1","1","1","2","2","1","1","2","1","1","2","2","1","1","2","1","2","1","2","3","3","3","4","3","4","3","4","3","4","4","4","4","3","4","3","4","4","4","4","3","4","3","3","3","3","3","3","3","4","4","4","4","3","4","3","3","4","4","4","4","3","4","4","4","4","4","4","4","4","5","3","5","5","5","5","4","5","5","5","5","5","5","3","3","5","5","5","5","3","5","3","5","3","5","5","3","3","5","5","5","5","5","3","3","5","5","5","3","5","5","5","5","5","5","3","5","5","3")
```
```{r}
df<-data.frame("V1"=as.numeric(v1),"V2"=as.numeric(v2),"Clust"=clust)
head(df)
```
Usually, you would do:
```{r}
ggplot(df, aes(V1,V2, color=Clust))+
geom_point()
```
But the colors might be confusing when having more than 8 categories. It's easier to do:
```{r}
ggplot(df, aes(V1,V2, color=Clust))+
geom_point()+
gglegend(df, V1, V2, Clust)+
guides(color="none")
```
## SEM
sem is just a small implementation to calculate the standard error of the mean. Useful for ploting errorbars with it.
```{r}
v<-rnorm(10)
sem(v)
```
## perc
perc transforms a numeric vector to percentage. Useful when using dplyr summarise function.
```{r}
v<-c(2,5,10,3)
perc(v)
# It can be used with dplyr tables
library(tidyverse)
df<-data.frame("X"=c("A","A","B","B"), "Y"=v)
df %>% group_by(X) %>% summarise(Y=perc(Y))
# Or it can be under 1
df %>% group_by(X) %>% summarise(Y=perc(Y, per100=F))
```