# Visualizing software metrics

I have the below sets of data per application, you can call them as software metrics. These metrics vary depending on the size of an application.

Bugs
CodeSmells
Vulnerability


The size of the application is determined by LOC (Lines of code), how can i showcase the complexity of each app relative to the lines of code if i visualize each of these parameters.

Example

           Bugs   LOC
SweetApp   10     10000
SourApp    120    5660000
SaltyApp   55     1500


How do i visualize Bugs per app in relation to the LOC, because LOC determines their complexity a higher number in bugs doesn't necessarily be bad considering a higher number in LOC.

You could use the ratios of bugs (or any other variable) divided by lines of code (LOC). Since ratios may vary a lot for instance bugs vs. vulnerabilities the resulting plot oftentimes doesn't look as good so you could use a normalization procedure, in fact, is the recommended procedure.

In your case Bugs and a few vulnerabilities divided by LOC doesn't look too bad so I included the plot of raw ratios too in this example. I'm using a count overlapping points plot which is a variant of a barplot that doesn't fill bars and only cares about the value as a point. You could use any normalization that you feel gives you the best result. Here I'm only centering the data. In both plots the highest value means higher complexity according to the ratio metric.

# Raw Ratios of variables divided by LOC # Normalized Ratios of variables divided by LOC ## Code in R needed to replicate these plots

require("reshape2")
require("ggplot2")

df1 <- data.frame(App = c("SweetApp", "SourApp", "SaltyApp"),
LOC = c(10000, 5660000, 1500),
Bugs = c(10, 120, 55),
CodeSmells = c(50, 30, 20),
Vulnerabilities = c(2, 3, 10))

#Define ratios
df1$RatiosBugs <- df1$Bugs / df1$LOC df1$RatiosCodeSmells <- df1$CodeSmells / df1$LOC
df1$RatiosVulnerabilities <- df1$Vulnerabilities / df1$LOC #Normalize Ratios df1$NormRatiosBugs <- scale(df1$RatiosBugs, scale = FALSE) df1$NormRatiosCodeSmells <- scale(df1$RatiosCodeSmells, scale = FALSE) df1$NormRatiosVulnerabilities <- scale(df1\$RatiosVulnerabilities, scale = FALSE)

dfRaw <- df1[, c("App", "RatiosBugs", "RatiosCodeSmells", "RatiosVulnerabilities")]
dfNorm <- df1[, c("App", "NormRatiosBugs",
"RatiosCodeSmells", "RatiosVulnerabilities")]
dfRaw.m <- melt(dfRaw, id.vars = c("App"))
dfNorm.m <- melt(dfNorm, id.vars = c("App"))

#Plot Raw Ratios
ggplot(dfRaw.m, aes(App, value)) +
geom_count(aes(color = variable), position = position_dodge(width =  0.4), stat = "identity")

#Plot Normalized Ratios
ggplot(dfNorm.m, aes(App, value)) +
geom_count(aes(color = variable), position = position_dodge(width = 0.4), stat = "identity")