Commit 69b35720 authored by dmattek's avatar dmattek

Order of clusters to display in trajPlot and clDist can be specified manually

parent 46cd43de
......@@ -110,8 +110,8 @@ getDataCl = function(in.dend, in.k) {
loc.dt.cl = data.table(id = names(loc.m),
cl = loc.m)
cat('===============\ndataCl:\n')
print(loc.dt.cl)
#cat('===============\ndataCl:\n')
#print(loc.dt.cl)
return(loc.dt.cl)
}
......@@ -134,8 +134,8 @@ getDataClSpar = function(in.dend, in.k, in.id) {
loc.dt.cl = data.table(id = in.id,
cl = loc.m)
cat('===============\ndataCl:\n')
print(loc.dt.cl)
#cat('===============\ndataCl:\n')
#print(loc.dt.cl)
return(loc.dt.cl)
}
......@@ -309,13 +309,13 @@ myGgplotTraj = function(dt.arg, # data table
userDataGen <- function() {
cat(file=stderr(), 'userDataGen: in\n')
locNtp = 40
locNtp = 60
locNtracks = 10
locNsites = 4
locNsites = 6
locNwells = 1
x.rand.1 = c(rnorm(locNtp * locNtracks * locNsites * 0.5, .5, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, 1, 0.2))
x.rand.2 = c(rnorm(locNtp * locNtracks * locNsites * 0.5, 0.25, 0.1), rnorm(locNtp * locNtracks * locNsites * 0.5, 0.5, 0.2))
x.rand.1 = c(rnorm(locNtp * locNtracks * locNsites * 1/3, 0.5, 0.1), rnorm(locNtp * locNtracks * locNsites * 1/3, 1, 0.2), rnorm(locNtp * locNtracks * locNsites * 1/3, 2, 0.5))
x.rand.2 = c(rnorm(locNtp * locNtracks * locNsites * 1/3, 0.25, 0.1), rnorm(locNtp * locNtracks * locNsites * 1/3, 0.5, 0.2), rnorm(locNtp * locNtracks * locNsites * 1/3, 1, 0.2))
# add NA's for testing
x.rand.1[c(10,20,30)] = NA
......
......@@ -29,14 +29,20 @@ modClDistPlot = function(input, output, session, in.data, in.cols = NULL, in.fna
return(NULL)
}
p.out = ggplot(loc.dt, aes(x = group, y = nCells)) +
geom_bar(aes(fill = as.factor(cl)), stat = 'identity', position = 'fill')
# Two statements: "position_fill(reverse = TRUE)" and "guide_legend(reverse = T)"
# result in stacked bar plot with categories ordered from the bottom to top of the stacked bar
p.out = ggplot(loc.dt[], aes(x = group, y = nCells)) +
geom_bar(aes(fill = as.factor(cl)), stat = 'identity', position = position_fill(reverse = TRUE)) +
guides(fill = guide_legend(reverse = T))
if(is.null(in.cols))
p.out = p.out + scale_fill_discrete(name = "Cluster no.")
else
p.out = p.out + scale_fill_manual(name = "Cluster no.",
values = in.cols()$cl.col)
values = in.cols()$cl.col) #,
#breaks = in.cols()$cl.no,
#labels = in.cols()$cl.no,
#limits = in.cols()$cl.no)
p.out = p.out +
......
......@@ -211,7 +211,17 @@ clustHier <- function(input, output, session, in.data4clust, in.data4trajPlot) {
if (is.null(loc.dend))
return(NULL)
return(getClCol(loc.dend, input$inPlotHierNclust))
loc.dt = getClCol(loc.dend, input$inPlotHierNclust)
# Display clusters specified in the inPlotHierClSel field
# Data is ordered according to the order of clusters specified in this field
if(input$chBPlotHierClSel) {
loc.dt = loc.dt[cl.no %in% input$inPlotHierClSel]
loc.dt[, cl.no := factor(cl.no, levels = input$inPlotHierClSel)]
setkey(loc.dt, cl.no)
}
return(loc.dt)
})
......@@ -260,9 +270,13 @@ clustHier <- function(input, output, session, in.data4clust, in.data4trajPlot) {
loc.dt.cl = getDataCl(userFitDendHier(), input$inPlotHierNclust)
loc.dt = merge(loc.dt, loc.dt.cl, by = 'id')
# display only selected clusters
if(input$chBPlotHierClSel)
# Display clusters specified in the inPlotHierClSel field
# Data is ordered according to the order of clusters specified in this field
if(input$chBPlotHierClSel) {
loc.dt = loc.dt[cl %in% input$inPlotHierClSel]
loc.dt[, cl := factor(cl, levels = input$inPlotHierClSel)]
setkey(loc.dt, cl)
}
return(loc.dt)
})
......@@ -304,12 +318,16 @@ clustHier <- function(input, output, session, in.data4clust, in.data4trajPlot) {
loc.dt = merge(loc.dt.cl, loc.dt.gr, by = 'id')
# display only selected clusters
if(input$chBPlotHierClSel)
loc.dt = loc.dt[cl %in% input$inPlotHierClSel]
loc.dt.aggr = loc.dt[, .(nCells = .N), by = .(group, cl)]
# Display clusters specified in the inPlotHierClSel field
# Data is ordered according to the order of clusters specified in this field
if(input$chBPlotHierClSel) {
loc.dt.aggr = loc.dt.aggr[cl %in% input$inPlotHierClSel]
loc.dt.aggr[, cl := factor(cl, levels = input$inPlotHierClSel)]
setkey(loc.dt.aggr, cl)
}
return(loc.dt.aggr)
})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment