Añadiendo la opción de excluir del agrupamiento.
This commit is contained in:
+3
-4
@@ -5,10 +5,10 @@ ggheatmap<-function(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_gro
|
|||||||
|
|
||||||
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{
|
||||||
df<-df %>% group_by(VarX,VarY,all_of(exclude_group))
|
df<-df %>% group_by_("VarX","VarY",exclude_group) #%>% rename(exclude_group="all_of(exclude_group)")
|
||||||
}
|
}
|
||||||
if (grouping == "mean"){
|
if (grouping == "mean"){
|
||||||
df<-df %>% summarise(Value=mean(Value)) %>% ungroup
|
df<-df %>% summarise(Value=mean(Value)) %>% ungroup
|
||||||
@@ -16,8 +16,7 @@ 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)
|
||||||
order<-clustsort(df %>% spread(VarY,Value) %>% as.data.frame)
|
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
+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")
|
ggheatmap(df, x=NULL, y=NULL, value=NULL, grouping="mean", exclude_group=NULL)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{df}{A data frame in "long" format.}
|
\item{df}{A data frame in "long" format.}
|
||||||
@@ -10,6 +10,7 @@ ggheatmap(df, x=NULL, y=NULL, value=NULL, grouping="mean")
|
|||||||
\item{y}{The variable that will be used for Y axis in the heatmap. If not specified, the second column will be used.}
|
\item{y}{The variable that will be used for Y axis in the heatmap. If not specified, the second column will be used.}
|
||||||
\item{value}{The variable that will be used for colouring the heatmap. If not specified, the third column will be used.}
|
\item{value}{The variable that will be used for colouring the heatmap. If not specified, the third column will be used.}
|
||||||
\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.}
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Generates a heatmap using ggplot for a dataframe.
|
Generates a heatmap using ggplot for a dataframe.
|
||||||
|
|||||||
Reference in New Issue
Block a user