问题描述
我使用名为“displayr”的应用程序创建了一个 sankey digaram,它会根据您上传的电子表格生成图表。但是,我想对节点的正确部分进行排序,使其更加直观。最好使用 R 代码按 DESC 对数据进行排序。我正在尝试找到有用的代码以及将其放入当前代码中的位置以实现它。
library(flipPlots)
library(flipData)
library(flipformat)
library(flipChartBasics)
weights <- NULL
dat <- NULL
dat <- get0("formTable")
if (is.null(dat))
{
if (exists("formEnteredData") && sum(dim(formEnteredData)) > 0)
dat <- flipTransformations::ParseEnteredData(formEnteredData)
}
if (is.null(dat))
{
dat <- as.data.frame(get0("formVariables"))
if (is.null(dat) || sum(dim(dat)) == 0)
stop("No data has been provided.")
weights <- QPopulationWeight
names(dat) <- if (!isTRUE(get0("formNames"))) Labels(formVariables) else Names(formVariables)
}
if (isTRUE(get0("formContainsWeights")))
{
weights <- dat[,ncol(dat)]
dat <- dat[,-ncol(dat)]
}
if (formTidyLabels)
names(dat) <- ExtractCommonPrefix(names(dat))$shortened.labels
dat <- TidyRawData(dat,weights = weights,subset = QFilter,missing = "Use partial data",error.if.insufficient.obs = FALSE)
sankey.dat <- SankeyDiagram(dat,max.categories = formMaxCategories,link.color = formlinkColors,subset = TRUE,weights = attr(dat,"weights"),variables.share.values = get0("formSharedValues",ifnotfound=FALSE),hovertext.show.percentages = formHoverPercentages,label.show.counts = formShowCounts,label.show.percentages = formShowPercentages,label.show.varname = formShowVar,label.max.length = formlabelMaxLen,output.data.only = TRUE)
num.colors <- length(unique(sankey.dat$nodes$group))
u.ind <- which(!duplicated(sankey.dat$nodes$group,fromLast = formlinkColors %in% c("Target","Last variable")))
u.names <- sankey.dat$nodes$name[u.ind]
# Different from 'Named colors' in other charts because nodes can be merged
# And questions names/counts/percentages may be included in node name
# we use partial matching.
template <- get0("formTemplate")
if (!is.null(template))
{
bcol <- rep(NA,num.colors)
names(bcol) <- u.names
col.list <- if (!is.null(template$brand.colors)) template$brand.colors else template$colors
col.names <- names(col.list)
col.ord <- order(nchar(col.names))
for (i in col.ord)
{
ind <- grep(paste0("\\Q",col.names[i],"\\E"),u.names)
if (length(ind) > 0)
bcol[ind] <- col.list[i]
}
template$brand.colors <- bcol
}
colors <- NULL
if (formPalette != "Legacy colors")
colors <- ChartColors(num.colors,given.colors = GetPalette(formPalette,template),custom.color = formCustomColor,custom.gradient.start = formCustomGradientStart,custom.gradient.end = formCustomGradientEnd,custom.palette = formCustomPalette,silent = TRUE)
if (is.null(template))
template <- list(global.font = list(family = "Arial",color = "#2C2C2C",size = 7.5,units = "pt"),fonts = list(`Values axis title` = list(
family = "Arial",size = 9)))
sankey <- SankeyDiagram(links.and.nodes = sankey.dat,colors = colors,sinks.right = formNodeRight,font.family = get0("formFontFamily",ifnotfound = template$fonts$`Values axis title`$family),font.size = get0("formFontSize",ifnotfound = template$fonts$`Values axis title`$size),font.unit = get0("formFontUnit",ifnotfound = template$global.font$units),node.width = formNodeWidth,node.padding = formNodePad)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)