psenovsky / MCDASupport

GNU General Public License v3.0
0 stars 0 forks source link

Graphing capabilities #7

Open psenovsky opened 2 months ago

psenovsky commented 2 months ago

At present time the package depends on two additional packages for graphing:

The package also depends on significant ammount of other packages for doing other things.

Consider to refactor the code so these two packages are recommended only. Which would requie testing for plotly/visNetwork availability on the target machine before utilizing these and use normal graphing capabilities if these are not installed on the machine.

Implementation for some graphs is available in previous versions of the package (not available in this repository ... will provide the code in follow up commentaries to this issue as a starting point).

psenovsky commented 2 months ago

For plot.scoreM the rewrite has been realized in v0.26, so the original code:

# plot.scoreM
#
# Specific function for an object of class scoreM for the generic function plot()
#
# Arguments:
#    PM - weighted preference matrix
#
# Returns
#   plot
plot.scoreM <- function(x, ...) {
  PM <- x
  #1. order the rows according to rowSums
  PM <- PM[order(rowSums(PM), decreasing = T),]
  #2. use a bar-plot of the transposed matrix
  tPM <- t(PM)
  ms  <- max(colSums(tPM)) * 1.25 #make room for legend
  alt <- sapply(lapply(colnames(tPM), strwrap, 10),
                paste, collapse = "\n")
  colnames(tPM) <- alt
  barplot(tPM,
          legend = T,
          ylab = 'Score',
          ylim = c(0, ms),
          col = rainbow(ncol(PM)),
          las = 2,
          args.legend = list(x = 'top', bty='n', ncol = 3),
          ...
  )
}
psenovsky commented 2 months ago

plot.prefM code from version 0.25:

# plot.prefM
#
# Specific function for an object of class prefM for the generic function plot()
#
# Arguments:
#    PM - weighted preference matrix
#
# Returns
#   plot
plot.prefM <- function(x, ...) {
  PM <- x
  if (!(is.matrix(PM) || (is.data.frame(PM)))) stop('wrong performance matrix, should be a matrix or a data frame')
  nr <- ncol(PM)
  if (nr != nrow(PM)) stop('Different number of alternatives in columns and rows')
  if (nr < 2) stop('less than 2 alternatives')
  i <- sapply(PM, is.numeric)
  if (length(i[i %in% F]) > 0) stop('Performance matrix must be numeric')

  X <- t(PM) # we want arrows to mean '... is better then ...' plotmat uses the
  # opposite convention because it expects flows
  plotmat(X,
          box.size = 0.1,
          cex.txt = 0,
          lwd = 5 * X, # lwd proportional to preference
          self.lwd = 3,
          lcol = 'blue',
          self.shiftx = c(0.06, -0.06, -0.06, 0.06),
          box.lcol = 'blue',
          box.col = 'khaki3',
          box.lwd = 2,
          relsize = 0.9,
          box.prop = 0.5,
          endhead = FALSE,
          main = '',
          ...)
}
psenovsky commented 2 months ago

rankGraph has been developed directly for the plotly, so no alternative implementation for it exists, yet.

All 3 functions (rankGraph, plot.scoreM and plot.prefM) needs to be adjustment for transition to the recommended to work.