Commit d1eaed16 authored by HaojiaWu's avatar HaojiaWu
Browse files

fix plot

parent 8f3cae92
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -6,12 +6,14 @@
#' This function can be used for plotting a single gene or multiple genes expression across 
#' different groups in a seurat featureplot format. 
#'
#' @param seu_obj A complete Seurat object
#' @param seu_obj A complete Seurat object.
#' @param features Gene names to be plotted.
#' @param group The group to show on y axis. One of the column names in meta.data.
#' @param select Select the elements within the group to show.
#' @param cols Change the color legend.
#' @param label.size Change the label size.
#' @param strip.color Colors for the strip background.
#' @param pt.size Point size for each cell.
#' @return A ggplot object
#' @export

@@ -21,8 +23,10 @@ complex_featureplot<-function(
  group, 
  select = NULL, 
  cols = NULL, 
  label.size=14, 
  order=F
  label.size = 12, 
  order = F, 
  strip.color = NULL,
  pt.size = 0.01
){
  gene_count<-extract_gene_count(seu_obj,features = features, meta.groups = group)
  if (is.null(levels(seu_obj@meta.data[,group]))){
@@ -51,12 +55,12 @@ complex_featureplot<-function(
  df_all$gene<-factor(df_all$gene, levels=features)
  if(order){
    df_all$isExpr<-ifelse(df_all$Exp>0, "Yes", "NO")
    p<-ggplot(df_all, aes(UMAP1, UMAP2))+geom_point(color="gray80",size=0.01)+
      geom_point(data = df_all[df_all$isExpr=="Yes",], aes(UMAP1, UMAP2, color=Exp), size=0.01)
    p<-ggplot(df_all, aes(UMAP1, UMAP2))+geom_point(color="gray80",size=pt.size)+
      geom_point(data = df_all[df_all$isExpr=="Yes",], aes(UMAP1, UMAP2, color=Exp), size=pt.size)
  } else {
    p<-ggplot(df_all, aes(UMAP1, UMAP2, color=Exp))+geom_point(size=0.01)
    p<-ggplot(df_all, aes(UMAP1, UMAP2, color=Exp))+geom_point(size=pt.size)
  }
  p +
  p<-p +
    scale_color_gradientn(colours  =  cols,
                          na.value = "white", limits=c(quantile(df_all$Exp, 0,na.rm= T), quantile(df_all$Exp, 1,na.rm= T)),
                          breaks = c(quantile(df_all$Exp, 0,na.rm= T), quantile(df_all$Exp, 1,na.rm= T)), labels = c("min","max"))+ 
@@ -65,9 +69,11 @@ complex_featureplot<-function(
          axis.line = element_blank(),
          axis.text = element_blank(),
          axis.title=element_blank(),
          strip.background = element_blank(),
          strip.text = element_text(size=label.size),
          legend.title = element_text(size = 12),
          legend.position="left")+
          legend.title = element_blank(),
          legend.key.size = unit(0.5, 'cm'),
          legend.position="bottom")+
    facet_grid(group ~ gene)
  g <- change_strip_background(p, type = 'both',  strip.color = strip.color)
  print(grid::grid.draw(g))
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -111,8 +111,8 @@ The violin plot will look too messy in this scenario so it is not included in pl

### 4. Umap geneplot across groups
```
png(filename =  'geneplot_umap.png', width = 4, height = 6,units = 'in', res = 100)
complex_featureplot(iri.integrated, features = c("Havcr1","Slc34a1"), group = "Group", select = c("Control","12hours","6weeks"), order = T)
png(filename =  'data/geneplot_umap.png', width = 8, height = 6,units = 'in', res = 100)
complex_featureplot(iri.integrated, features = c("Havcr1",  "Slc34a1", "Vcam1",   "Krt20"  , "Slc7a13"), group = "Group", select = c("Control","12hours","6weeks"), order = F)
dev.off()
```
![alt text](https://github.com/HaojiaWu/Plot1cell/blob/master/data/geneplot_umap.png) <br />
+29.3 KiB (81.4 KiB)
Loading image diff...
+9 −3
Original line number Diff line number Diff line
@@ -10,12 +10,14 @@ complex_featureplot(
  group,
  select = NULL,
  cols = NULL,
  label.size = 14,
  order = F
  label.size = 12,
  order = F,
  strip.color = NULL,
  pt.size = 0.01
)
}
\arguments{
\item{seu_obj}{A complete Seurat object}
\item{seu_obj}{A complete Seurat object.}

\item{features}{Gene names to be plotted.}

@@ -26,6 +28,10 @@ complex_featureplot(
\item{cols}{Change the color legend.}

\item{label.size}{Change the label size.}

\item{strip.color}{Colors for the strip background.}

\item{pt.size}{Point size for each cell.}
}
\value{
A ggplot object