Merge branch 'main' of https://git.ratg.cat/marcelcosta/CitFuns into main
This commit is contained in:
+10
-6
@@ -1,10 +1,10 @@
|
|||||||
ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none"){
|
ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none",color="#FFFFFF00"){
|
||||||
if (is.null(x)){x=colnames(df)[1]}
|
if (is.null(x)){x=colnames(df)[1]}
|
||||||
if (is.null(y)){y=colnames(df)[2]}
|
if (is.null(y)){y=colnames(df)[2]}
|
||||||
if (is.null(value)){value=colnames(df)[3]}
|
if (is.null(value)){value=colnames(df)[3]}
|
||||||
|
|
||||||
df<-rename(df, "VarX"=all_of(x), "VarY"=all_of(y), "Value"=all_of(value))
|
df<-rename(df, "VarX"=all_of(x), "VarY"=all_of(y), "Value"=all_of(value))
|
||||||
|
|
||||||
if (is.null(exclude_group)){
|
if (is.null(exclude_group)){
|
||||||
df<-df %>% group_by(VarX,VarY)
|
df<-df %>% group_by(VarX,VarY)
|
||||||
}else{
|
}else{
|
||||||
@@ -17,7 +17,7 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro
|
|||||||
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)
|
order<-clustsort(df %>% spread(VarY,Value) %>% select(!all_of(exclude_group)) %>% as.data.frame)
|
||||||
|
|
||||||
if (scale != "none"){
|
if (scale != "none"){
|
||||||
if (scale == "rows"){
|
if (scale == "rows"){
|
||||||
cols<-unique(df$VarY)
|
cols<-unique(df$VarY)
|
||||||
@@ -32,12 +32,16 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro
|
|||||||
df<-gather(sca.df, VarX, Value, all_of(cols))
|
df<-gather(sca.df, VarX, Value, all_of(cols))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
df$VarX<-factor(df$VarX, levels=order$x)
|
df$VarX<-factor(df$VarX, levels=order$x)
|
||||||
df$VarY<-factor(df$VarY, levels=order$y)
|
df$VarY<-factor(df$VarY, levels=order$y)
|
||||||
|
|
||||||
df %>%
|
df %>%
|
||||||
ggplot(aes(VarX, VarY, fill=Value))+
|
ggplot(aes(VarX, VarY, fill=Value))+
|
||||||
labs(x=x, y=y)+
|
labs(x=x, y=y)+
|
||||||
theme_heatmap()
|
geom_tile(aes(fill=Value), color=color)+
|
||||||
|
scale_fill_gradientn(colors=col2(200))+
|
||||||
|
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=0.5),
|
||||||
|
panel.background = element_blank(),
|
||||||
|
axis.ticks = element_blank())
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -2,7 +2,7 @@
|
|||||||
\alias{ggheatmap}
|
\alias{ggheatmap}
|
||||||
\title{ggheatmap}
|
\title{ggheatmap}
|
||||||
\usage{
|
\usage{
|
||||||
ggheatmap(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none")
|
ggheatmap(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, scale="none", color="#FFFFFF00")
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{df}{A data frame in "long" format.}
|
\item{df}{A data frame in "long" format.}
|
||||||
@@ -12,6 +12,7 @@ ggheatmap(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL, s
|
|||||||
\item{grouping}{The function that will be used to group if there is more than one observation for each X-Y combination. "mean" or "median" are posible, defaulting to "mean".}
|
\item{grouping}{The function that will be used to group if there is more than one observation for each X-Y combination. "mean" or "median" are posible, defaulting to "mean".}
|
||||||
\item{exclude_group}{If you want to exclude columns from grouping, you can introduce a character vector here. Useful if you want to facet the plot.}
|
\item{exclude_group}{If you want to exclude columns from grouping, you can introduce a character vector here. Useful if you want to facet the plot.}
|
||||||
\item{scale}{Escales (z-score) by "rows" or "cols" if diferent of "none" (default).}
|
\item{scale}{Escales (z-score) by "rows" or "cols" if diferent of "none" (default).}
|
||||||
|
\item{color}{The color of the lines of geom_tile (the border). By default, its transparent.}
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Generates a heatmap using ggplot for a dataframe.
|
Generates a heatmap using ggplot for a dataframe.
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ You will also need [Git](https://git-scm.com/downloads) installed in your comput
|
|||||||
|
|
||||||
Now we are ready to install CitFuns package:
|
Now we are ready to install CitFuns package:
|
||||||
```{r, eval=F}
|
```{r, eval=F}
|
||||||
devtools::install_git("https://git.ratg.cat/marcelcosta/CitFuns.git")
|
devtools::install_git("https://git.ratg.cat/marcelcosta/CitFuns.git", build_vignettes = T)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Update
|
## Update
|
||||||
@@ -123,8 +123,15 @@ By default, ggcorrplot converts the p-value into *star* significance equivalence
|
|||||||
ggcorrplot(df, var = "Cyt", value = "Value", color = "white", stat="pval")
|
ggcorrplot(df, var = "Cyt", value = "Value", color = "white", stat="pval")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
ggcorrplot uses "pearson" by default to obtain a correlation coeficient, although "spearman" is also available.
|
||||||
|
|
||||||
|
```{r, fig.width=5, fig.height=4}
|
||||||
|
ggcorrplot(df, var = "Cyt", value = "Value", color = "white", stat="pval", method="spearman")
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Finally, you can show only the upper part or the lower part of the specular matrix.
|
Finally, you can show only the upper part or the lower part of the specular matrix.
|
||||||
|
|
||||||
```{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")
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user