factorForGraph: Factor one column by another column's popularity

Description Usage Arguments Value Examples

Description

Factor (or refactor) a data frame of values to be used for graphing in the correct order.

Many graphs require a reordering when plotting with a fill value. This helper function factors the x-value of a plot that will be stacked by fillVal.

Usage

1
factorForGraph(df, xVal, fillVal, decFill = TRUE)

Arguments

df

A data frame containing the x and fill value columns.

xVal

A character value from a header name in df that will be used as the x value in a ggplot2 plot.

fillVal

A character value from a header name in df that will be used as the fill value in a ggplot2 plot.

decFill

Sort fill value in decreasing order.

Value

A data frame with two of the columns factored.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sumo <- cleanPatentData(patentData = patentr::acars, columnsExpected = sumobrainColumns,
cleanNames = sumobrainNames,
dateFields = sumobrainDateFields,
dateOrders = sumobrainDateOrder,
deduplicate = TRUE,
cakcDict = patentr::cakcDict,
docLengthTypesDict = patentr::docLengthTypesDict,
keepType = "grant",
firstAssigneeOnly = TRUE, 
assigneeSep = ";",
stopWords = patentr::assigneeStopWords)

# note that in reality, you need a patent analyst to carefully score
# these patents, the score here is for demonstrational purposes
score <- round(rnorm(dim(sumo)[1],mean=1.4,sd=0.9))
score[score>3] <- 3
score[score<0] <- 0
sumo$score <- score
dim(sumo)
sumoFactor <- factorForGraph(sumo, "assigneeClean", "score")
# if you want to view, uncomment and load ggplot2
# ggplot(sumoFactor, aes(x=assigneeClean, y=score, fill=factor(score))) + 
# geom_bar(stat="identity")

kamilien1/patentR documentation built on May 20, 2019, 7:19 a.m.