lc
Plots a line chart, the values of the variable ordered according to their order in the data frame. Usually this ordering would be an ordering according to time, which yields a run chart. The default run chart provides the index, that is, sequential position, of each value of the variable from 1 to the last value. Optionally dates can be provided so that a time-series plot is produced.
For data of one variable exhibiting little trend, the center line is provided for the generation of a run chart, plotting the values of a variable in order of occurrence over time. When the center line, the median by default, is plotted, the analyses of the number and composition of the individual runs, number of consecutive values above or below the center line, is also displayed. Also, the defaults change for each of the types of plots. The intent is to rely on the default values for a relatively sophisticated plot, particularly when compared to the default values of the standard R plot
function called with a single variable.
If the provided object to analyze is a set of multiple variables, including an entire data frame, then each non-numeric variable in the data frame is analyzed and the results written to a pdf file in the current working directory. The name of each output pdf file that contains a bar chart and its path are specified in the output.
LineChart(x, data=mydata, n.cat=getOption("n.cat"), type=NULL, col.fill=getOption("col.fill.bar"),
col.stroke=getOption("col.stroke.pt"),
col.bg=getOption("col.bg"),
col.grid=getOption("col.grid"),
col.line=getOption("col.stroke.pt"),
col.area=NULL, col.box="black",
shape.pts=21, cex.axis=.75, col.axis="gray30",
rotate.values=0, offset=.5,
xy.ticks=TRUE, line.width=1.1,
xlab=NULL, ylab=NULL, main=NULL, sub=NULL, cex=NULL,
time.start=NULL, time.by=NULL, time.reverse=FALSE,
center.line=c("default", "mean", "median", "zero", "off"),
show.runs=FALSE, quiet=getOption("quiet"),
pdf.file=NULL, pdf.width=5, pdf.height=5, ...)
lc(...)
c
mydata
."p"
for
points, "l"
for line, or "b"
for both. The default is
"b"
for both points and lines.col.stroke
."grey90"
."darkblue"
."transparent"
."black"
.col.stroke
and col.fill
. col.fill
defaults tooffset
.xlab
not
specified, then the label becomes the name of the corresponding variable. If
xy.ticks
is FALSE
, then no label is displayed. If no y vxy.ticks
is FALSE
, then no label displayed.x.reverse
, the first date is after
the data are reverse sorted. Not needed if data are a time series with
time.start
specification, the interval to increment the
date for each sequential data value. A character string, containing one of "day"
,
"week"
, "month"
or "year"
TRUE
, reverse the ordering of the dates, particularly when the
data are listed such that first row of data is the newest. Accompanies the time.start
specification."mean"
and "median"
. Provides a centerline
for the "median"
by default when the values randomly vary aboutTRUE
, display the individual runs in the run analysis.TRUE
, no text output. Can change system default
with set
function..pdf
, the filetype is added to the name.par
, col.lab
,
sub
, col.sub
, col.ticks
to set the color of the
ticks used to label the axis values, and
<plot
when called with only a single variable.The values on the horizontal axis of the line chart are automatically generated. The default is the index variable, the ordinal position of each data value, in which case this version of the line chart is a run chart. Or, dates on the horizontal axis can be specified from the specified starting date given by x.start
and the accompanying increment as given by x.by
, in which case the line chart is typically referred to as a time series chart.
If the data values randomly vary about the mean, the default is to plot the mean as the center line of the graph, otherwise the default is to ignore the center line. The default plot type for the line chart is type="b"
, for both points and the corresponding connected line segments. The size of the points is automatically reduced according to the number of points of points plotted, and the cex
option can override the computed default. If the area below the plotted values is specified to be filled in with color, then the default line type changes to type="l"
.
DATA
The data may either be a vector from the global environment, the user's workspace, as illustrated in the examples below, or one or more variable's in a data frame, or a complete data frame. The default input data frame is mydata
. Can specify the source data frame name with the data
option. If multiple variables are specified, only the numerical variables in the list of variables are analyzed. The variables in the data frame are referenced directly by their names, that is, no need to invoke the standard R
mechanisms of the mydata$name
notation, the with
function or the attach
function. If the name of the vector in the global environment and of a variable in the input data frame are the same, the vector is analyzed.
COLORS
Individual colors in the plot can be manipulated with options such as col.stroke
for the color of the border of the plotted points. A color theme for all the colors can be chosen for a specific plot with the colors
option with the lessR
function set
. The default color theme is dodgerblue
, but a gray scale is available with "gray"
, and other themes are available as explained in set
, such as "red"
and "green"
. Use the option ghost=TRUE
for a black background, no grid lines and partial transparency of plotted colors.
VARIABLE LABELS
Although standard R does not provide for variable labels, lessR
does, obtained from the Read
function. If the variable labels exist, then the corresponding variable label is by default listed as the label for the horizontal axis and on the text output. For more information, see Read
.
PDF OUTPUT
Because of the customized graphic windowing system that maintains a unique graphic window for the Help function, the standard graphic output functions such as pdf
do not work with the lessR
graphics functions. Instead, to obtain pdf output, use the pdf.file
option, perhaps with the optional pdf.width
and pdf.height
options. These files are written to the default working directory, which can be explicitly specified with the R setwd
function.
ONLY VARIABLES ARE REFERENCED
The referenced variable in a lessR
function can only be a variable name (or list of variable names). This referenced variable must exist in either the referenced data frame, such as the default mydata
, or in the user's workspace, more formally called the global environment. That is, expressions cannot be directly evaluated. For example:
> LineChart(rnorm(50)) # does NOT work}
Instead, do the following: > Y <- rnorm(50) # create vector Y in user workspace > LineChart(Y) # directly reference Y
[object Object],[object Object]
# default run chart LineChart(Y) # short name lc(Y) # compare to standard R plot plot(mydata$Y, type="l")
# save run chart to a pdf file LineChart(Y, pdf.file="MyLineChart.pdf")
# LineChart in gray scale, then back to default "dodgerblue" theme(colors="gray") LineChart(Y) theme(colors="dodgerblue") # customize run chart with LineChart options LineChart(Y, line.width=2, col.stroke="sienna3", col.area="slategray3", col.bg="mintcream", center.line="median")
# customize run chart with R par parameters # 24 is the R value for a half-triangle pointing up lc(Y, xlab="My xaxis", ylab="My yaxis", main="My Best Title", cex.axis=.7, cex.lab=1.2, cex.main=1.5, col.lab="red", font.main=3, ylim=c(-4,4), shape.pts=24) # generate steadily increasing values Y <- sort(rexp(50)) # default line chart LineChart(Y) # line chart with border around plotted values LineChart(Y, col.area="transparent") # time series chart, i.e., with dates, and filled area # with option label for the x-axis LineChart(Y, time.start="2000/09/01", time.by="3 months") # time series chart from a time series object y.ts <- ts(Y, start=c(2000, 9), frequency=4) LineChart(y.ts)
# LineChart with built-in data set LineChart(breaks, data=warpbreaks)
# Line charts for all numeric variables in a data frame LineChart()
# Line charts for all specified numeric variables in a list of variables
# e.g., use the combine or c function to specify a list of variables
LineChart(c(X,Y))