knitr::opts_chunk$set(echo=TRUE, fig.width=4.5, fig.height=3.25)
library(lessR)
##
## lessR 3.9.0 feedback: gerbing@pdx.edu web: lessRstats.com/new
## ---------------------------------------------------------------------
## 1. d <- Read("") Read text, Excel, SPSS, SAS or R data file
## d: default data frame, no need for data=
## 2. l <- Read("", var_labels=TRUE) Read variable labels into l,
## required name for data frame of labels
## 3. Help() Get help, and, e.g., Help(Read)
## 4. hs(), bc(), or ca() All histograms, all bar charts, or both
## 5. Plot(X) or Plot(X,Y) For continuous and categorical variables
## 6. by1= , by2= Trellis graphics, a plot for each by1, by2
## 7. reg(Y ~ X, Rmd="eg") Regression with full interpretative output
## 8. style("gray") Grayscale theme, + many others available
## style(show=TRUE) all color/style options and current values
## 9. getColors() create many styles of color palettes
##
## lessR parameter names now use _'s. Names with a period are deprecated.
## Ex: bin_width instead of bin.width
library(lessR)
Default data frame: d, though older default mydata still works, but deprecated
Parameter names: Underscore _ replaces period ., though the . still works, but deprecated
Read data sets distributed with lessR just by specifying the name of the data set.
d <- Read("Cars93")
##
## >>> Suggestions
## Details about your data, Enter: details() for d, or details(name)
##
## Data Types
## ------------------------------------------------------------
## character: Non-numeric data values
## integer: Numeric data values, integers only
## double: Numeric data values with decimal digits
## ------------------------------------------------------------
##
## Variable Missing Unique
## Name Type Values Values Values First and last values
## ------------------------------------------------------------------------------------------
## 1 Make character 93 0 32 Acura Acura ... Volvo Volvo
## 2 Type character 93 0 6 Small Midsize ... Compact Midsize
## 3 MinPrice double 93 0 79 12.9 29.2 25.9 ... 22.9 21.8 24.8
## 4 MidPrice double 93 0 81 15.9 33.9 29.1 ... 23.3 22.7 26.7
## 5 MaxPrice double 93 0 79 18.8 38.7 32.3 ... 23.7 23.5 28.5
## 6 MPGcity integer 93 0 21 25 18 20 ... 18 21 20
## 7 MPGhiway integer 93 0 22 31 25 26 ... 25 28 28
## 8 Airbags integer 93 0 3 0 2 1 ... 0 1 2
## 9 DriveTrain integer 93 0 3 1 1 1 ... 1 0 1
## 10 Cylinders integer 92 1 5 4 6 6 ... 6 4 5
## 11 Engine double 93 0 26 1.8 3.2 2.8 ... 2.8 2.3 2.4
## 12 HP integer 93 0 57 140 200 172 ... 178 114 168
## 13 RPM integer 93 0 24 6300 5500 5500 ... 5800 5400 6200
## 14 RevMile integer 93 0 78 2890 2335 2280 ... 2385 2215 2310
## 15 Manual integer 93 0 2 1 1 1 ... 1 1 1
## 16 FuelCap double 93 0 38 13.2 18 16.9 ... 18.5 15.8 19.3
## 17 PassCap integer 93 0 6 5 5 5 ... 4 5 5
## 18 Length integer 93 0 51 177 195 180 ... 159 190 184
## 19 Wheelbase integer 93 0 27 102 115 102 ... 97 104 105
## 20 Width integer 93 0 16 68 71 67 ... 66 67 69
## 21 Uturn integer 93 0 14 37 38 37 ... 36 37 38
## 22 RearSeat double 91 2 24 26.5 30 28 ... 26 29.5 30
## 23 LugCap integer 82 11 16 11 15 14 ... 15 14 15
## 24 Weight integer 93 0 81 2705 3560 3375 ... 2810 2985 3245
## 25 Source integer 93 0 2 0 0 0 ... 0 0 0
## ------------------------------------------------------------------------------------------
The grays were getting boring. Default is to label the bars with percentages.
BarChart(Type)
## >>> Suggestions
## BarChart(Type, horiz=TRUE) # horizontal bar chart
## BarChart(Type, fill="greens") # sequential green bars
## PieChart(Type) # doughnut (ring) chart
## Plot(Type) # bubble plot
## Plot(Type, stat="count") # lollipop plot
##
##
## --- Type ---
##
##
## Missing Values of Type: 0
##
##
## Compact Large Midsize Small Sporty Van Total
## Frequencies: 16 11 22 21 14 9 93
## Proportions: 0.172 0.118 0.237 0.226 0.151 0.097 1.000
##
##
## Chi-squared test of null hypothesis of equal probabilities
## Chisq = 8.871, df = 5, p-value = 0.114
Plot(MPGcity)
## [Violin/Box/Scatterplot graphics from Deepayan Sarkar's lattice package]
## >>> Suggestions
## Plot(MPGcity, out_cut=2, fences=TRUE, vbs_mean=TRUE) # Label two outliers ...
## Plot(MPGcity, box_adj=TRUE) # Adjust boxplot whiskers for asymmetry
##
## --- MPGcity ---
## Present: 93
## Missing: 0
## Total : 93
##
## Mean : 22.37
## Stnd Dev : 5.62
## IQR : 7.00
## Skew : 0.20 [medcouple, -1 to 1]
##
## Minimum : 15.00
## Lower Whisker: 15.00
## 1st Quartile : 18.00
## Median : 21.00
## 3rd Quartile : 25.00
## Upper Whisker: 33.00
## Maximum : 46.00
##
##
## (Box plot) Outliers: 3
##
## Small Large
## ----- -----
## Metro 46.0
## Civic 42.0
## Swift 39.0
##
##
## Max Dupli-
## Level cations Values
## ------------------------------
## MPGcity 12 18
##
##
## Parameter values (can be manually set)
## -------------------------------------------------------
## size: 0.57 size of plotted points
## jitter_y: 1.38 random vertical movement of points
## jitter_x: 0.33 random horizontal movement of points
## bw: 3.36 set bandwidth higher for smoother edges
Much better control of margins, including when rotate_x is set to 90 (perpendicular to axis). Also when the text output becomes too wide, horizontal width of the console the output realigns to vertical.
BarChart(Make, rotate_x=90)
## >>> Suggestions
## BarChart(Make, horiz=TRUE) # horizontal bar chart
## BarChart(Make, fill="greens") # sequential green bars
## PieChart(Make) # doughnut (ring) chart
## Plot(Make) # bubble plot
## Plot(Make, stat="count") # lollipop plot
##
##
## --- Make ---
##
##
## Missing Values of Make: 0
##
##
## Make Count Prop
## --------------------------
## Acura 2 0.022
## Audi 2 0.022
## BMW 1 0.011
## Buick 4 0.043
## Cadillac 2 0.022
## Chevrolet 8 0.086
## Chrylser 1 0.011
## Chrysler 2 0.022
## Dodge 6 0.065
## Eagle 2 0.022
## Ford 8 0.086
## Geo 2 0.022
## Honda 3 0.032
## Hyundai 4 0.043
## Infiniti 1 0.011
## Lexus 2 0.022
## Lincoln 2 0.022
## Mazda 5 0.054
## Mercedes-Benz 2 0.022
## Mercury 2 0.022
## Mitsubishi 2 0.022
## Nissan 4 0.043
## Oldsmobile 4 0.043
## Plymouth 1 0.011
## Pontiac 5 0.054
## Saab 1 0.011
## Saturn 1 0.011
## Subaru 3 0.032
## Suzuki 1 0.011
## Toyota 4 0.043
## Volkswagen 4 0.043
## Volvo 2 0.022
## --------------------------
## Total 93 1.000
##
##
## Chi-squared test of null hypothesis of equal probabilities
## Chisq = 38.785, df = 31, p-value = 0.159
## >>> Low cell expected frequencies, so chi-squared approximation may not be accurate
##
style(quiet=TRUE)
BarChart(Make, horiz=TRUE)
Label and margin positions can now be customized regardless of what the margin algorithm produces. + values move the corresponding label or margin away from plot edge. Not applicable to Trellis graphics.
Parameter lab_adj is a two-element vector – x-axis label, y-axis label – adjusts the position of the axis labels in approximate inches. + values move the labels away from plot edge. Not applicable to Trellis graphics.
Parameter margin_adj is a four-element vector – top, right, bottom and left – adjusts the margins of the plotted figure in approximate inches.
BarChart(Type, label.adj=c(.5,.5), margin_adj=c(0,0,.5,.5))
Sorting possible.
BarChart(Make, rotate_x=90, sort="+")
d <- rd("Mach4")
l <- rd("http://lessRstats.com/data/Mach4_lbl.xlsx", var_labels=TRUE)
Long variable labels accommodated.
Plot(Gender, m06, value_labels=c("Male", "Female"))
However, good for the user to have a choice, with the new scale.x and scale.y parameters, each a vector with the start value, end value and number of increments.
d <- rd("Employee", quiet=TRUE)
Histogram(Salary, scale.x=c(30000,130000,5), scale_y=c(0,9.5,5))
The getColors() function provides much flexibility to generate colors. Parameter c is chroma, amount of gray, and l is luminance, or brightness.
BarChart(Dept, fill=getColors(c=88, l=40))
BarChart(Dept, fill=getColors(c=88, l=80))
Many pre-defined color palettes are available, across the 360 degrees of the color wheel: “reds”, “rusts”, “browns”, “olives”, “greens”, “emeralds”, “turquoise”, “aquas”, “blues”, “purples”, “violets” , “magentas”, “grays”.
BarChart(Dept, fill="greens")