Skip to content
This repository has been archived by the owner on Jan 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #71 from ThomsonReuters-LSPS/fix-timepoints-for-li…
Browse files Browse the repository at this point in the history
…ne-graph

Fix timepoints for line graph
  • Loading branch information
Terry-Weymouth committed Apr 21, 2016
2 parents cd10a79 + a3b35d5 commit d4b7c89
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions web-app/Rscripts/LineGraph/LineGraphLoader.r
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ LineGraph.loader <- function(
scaling.data <- read.delim(scaling.filename, header=T, stringsAsFactors = FALSE)
}
} else { # if scaling file is not available, each level of group (concept path) will be plotted at the number of that level
scaling.data <- data.frame(GROUP = unique(line.data$GROUP), VALUE = 1:length(unique(line.data$GROUP)))
scaling.data <- data.frame(GROUP = unique(line.data$GROUP), VALUE = 1:length(unique(line.data$GROUP)), stringsAsFactors = FALSE)
}
# assign the X-axis position to each row
line.data$TIME_VALUE <- sapply(line.data$GROUP,FUN = function(groupValue) { scaling.data$VALUE[which(groupValue==scaling.data$GROUP)] })
line.data$TIME_VALUE <- sapply(line.data$GROUP,FUN = function(groupValue) {
scaling.data$VALUE[which(substring(scaling.data$GROUP, nchar(scaling.data$GROUP)-nchar(groupValue)+1)==groupValue)]
})

# Either plot a single LineGraph (if there are no plot_group values)
# or, for each group-value, retrieve rows for that value and plot LineGraph
Expand Down Expand Up @@ -102,7 +104,7 @@ LineGraph.plotter <- function(
#Use a regular expression trim out the timepoint from the concept.
#dataOutput$TIMEPOINT <- str_extract(dataOutput$TIMEPOINT,"Week [0-9]+")
dataOutput$TIMEPOINT <- as.character(dataOutput$TIMEPOINT)
TIMEPOINT_reducedConceptPath <- str_extract(dataOutput$TIMEPOINT,"(\\\\.+\\\\.+\\\\)+?$")
TIMEPOINT_reducedConceptPath <- str_extract(dataOutput$TIMEPOINT,"(\\\\[^\\\\]+\\\\[^\\\\]+\\\\)$")
validReplacements <- which(!is.na(TIMEPOINT_reducedConceptPath))
dataOutput$TIMEPOINT[validReplacements] <- TIMEPOINT_reducedConceptPath[validReplacements]
dataOutput$TIMEPOINT <- as.factor(dataOutput$TIMEPOINT)
Expand Down

0 comments on commit d4b7c89

Please sign in to comment.