Commit 22344406 authored by HaojiaWu's avatar HaojiaWu
Browse files

bug fixes

parent 5ff148b1
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -161,6 +161,8 @@ prepare_circlize_data <- function(
#' @param pt.size Point size of the graph
#' @param kde2d.n Number of grid points in each direction. A kde2d parameter
#' @param contour.nlevels Total number of levels in contour
#' @param col.use Colors used to label the cell type
#' @param repel Whether or not to repel the cell type names on umap
#' @return Return a circlize plot
#' @export
plot_circlize <- function(
@@ -171,7 +173,8 @@ plot_circlize <- function(
  kde2d.n = 1000,
  contour.nlevels = 100,
  bg.color='#F9F2E4',
  col.use=NULL
  col.use=NULL,
  repel=FALSE
  ) {
  data_plot %>%
    dplyr::group_by(Cluster) %>%
@@ -207,9 +210,13 @@ plot_circlize <- function(
  points(data_plot$x,data_plot$y, pch = 19, col = alpha(data_plot$Colors,0.2), cex = pt.size);
  contour(z, drawlabels=F, nlevels= 100, levels = contour.levels,col = '#ae9c76', add=TRUE)
  if(do.label){
    if(repel){
      textplot(x=centers$x, y=centers$y, words =  centers$Cluster,cex = 0.8, new = F,show.lines=F)
    } else {
      text(centers$x,centers$y, labels=centers$Cluster, cex = 0.8, col = 'black')
    }
  } 
}

#' Add tracks to the circlize plot
#'
+4 −4
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ iri.integrated <- Install.example()

# Please note that this Seurat object is just for demo purpose and 
# is not exactly the same as we published on PNAS.
# It take about 2 hours to run in a linux server with 500GB RAM and 32 CPU cores.
# It takes about 2 hours to run in a linux server with 500GB RAM and 32 CPU cores.
# You can skip this step and use your own Seurat object instead
```

@@ -29,12 +29,12 @@ colnames(iri.integrated@meta.data)
circ_data <- prepare_circlize_data(iri.integrated, scale = 0.8 )
set.seed(1234)
cluster_colors<-rand_color(length(levels(iri.integrated)))
group_colors<-rand_color(length(table(iri.integrated$Group)))
rep_colors<-group_colors<-rand_color(length(table(iri.integrated$orig.ident)))
group_colors<-rand_color(length(names(table(iri.integrated$Group))))
rep_colors<-rand_color(length(names(table(iri.integrated$orig.ident))))

###plot and save figures
png(filename =  'circlize_plot.png', width = 6, height = 6,units = 'in', res = 300)
plot_circlize(circ_data,do.label = T, pt.size = 0.01, col.use = cluster_colors ,bg.color = 'white', kde2d.n = 200)
plot_circlize(circ_data,do.label = T, pt.size = 0.01, col.use = cluster_colors ,bg.color = 'white', kde2d.n = 200, repel = T)
add_track(circ_data, group = "Group", colors = group_colors) ## can change it to one of the columns in the meta data of your seurat object
add_track(circ_data, group = "orig.ident",colors = rep_colors) ## can change it to one of the columns in the meta data of your seurat object
dev.off()
+114 KiB (941 KiB)
Loading image diff...
+6 −1
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@ plot_circlize(
  kde2d.n = 1000,
  contour.nlevels = 100,
  bg.color = "#F9F2E4",
  col.use = NULL
  col.use = NULL,
  repel = FALSE
)
}
\arguments{
@@ -29,6 +30,10 @@ plot_circlize(
\item{contour.nlevels}{Total number of levels in contour}

\item{bg.color}{Canvas background color}

\item{col.use}{Colors used to label the cell type}

\item{repel}{Whether or not to repel the cell type names on umap}
}
\value{
Return a circlize plot