library(lessR)
##
## lessR 3.7.3 feedback: gerbing@pdx.edu web: lessRstats.com
## ---------------------------------------------------------------------
## 1. mydata <- Read() Read text, Excel, SPSS, SAS or R data file
## 2. Help() Get help
## 3. hs(), bc(), or ca() All histograms, all bar charts, or both
## 4. Plot(X) or Plot(X,Y) For continuous and categorical variables
## numerical X: Violin, Box, Scatter plot
## 5. by1= , by2= Trellis graphics, a plot for each by1, by2
## 6. reg(Y ~ X, Rmd="eg") Regression + R markdown file that, when
## knit, provides full interpretative output
## 7. style("gold", sub.theme="black") Set theme, optional sub.theme
## style(show=TRUE) all color/style options and current values
## 8. getColors() create discrete, continuous color scales
mydata <- rd("Cars93", format="lessR", quiet=TRUE)
The grays were getting boring. Now a blue complement to the lightbronze background fills in bars, points, and the violin plot, which has a lighter blue fill than the others.
BarChart(Type)
## >>> Suggestions
## Plot(Type) # bubble plot
## Plot(Type, values="count") # lollipop plot
## BarChart(Type, horiz=TRUE) # horizontal bar chart
## BarChart(Type, fill="colors", color="off") # hcl bar colors
## PieChart(Type) # doughnut chart
##
##
## --- Type ---
##
##
## 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
## ----- -----
## 39 46.0
## 42 42.0
## 83 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 exceeds the horizontal width of the console the output realigns to vertical.
BarChart(Make, rotate.x=90)
## >>> Suggestions
## Plot(Make) # bubble plot
## Plot(Make, values="count") # lollipop plot
## BarChart(Make, horiz=TRUE) # horizontal bar chart
## BarChart(Make, fill="colors", color="off") # hcl bar colors
## PieChart(Make) # doughnut chart
##
##
## --- Make ---
##
##
## 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
##
Moving the category axis to horizontal jams the axis values. One solution is to raise the vertical height of the plot.
style(quiet=TRUE)
BarChart(Make, horiz=TRUE)
Margins can now be customized regardless of what the margin algrothim produces. Use bm.adj, lm.adj, tm.adj, and rm.adj to adust the respective margin in inches. Use xlab.adj and ylab.adj to adjust the labels, which are indicated in lines not inches. Negative numbers move left or down, positive numbers right up.
BarChart(Type, bm.adj=.5, xlab.adj=.5, lm.adj=.5, ylab.adj=.5)
style(quiet=TRUE)
BarChart(Make, rotate.x=90, sort.x="down")
BarChart(Make, rotate.x=90, sort.x="up")
Go to the Mach IV scale and associated variable labels, that is, item content.
mydata <- rd("Mach4", format="lessR", quiet=TRUE)
mylabels <- vl("http://lessRstats.com/data/Mach4_lbl.xlsx")
Particularly for survey data where items are natural variable labels, accomodating long labels is best.
Plot(Gender, m06, value.labels=c("Male", "Female"))
Plot(m10, m13)
With this data configuration the height of the largest bar extends past the highest value on the axis. R chooses by default to keep the axis values “pretty”. If it kept those same values and extended the axis there would be much wasted space.
mydata <- rd("Employee", format="lessR", quiet=TRUE)
mydata[2,4] <- 45000
Histogram(Salary)
However, good for the user to have a choice, with the new scale.x and scale.y paramters, each a vector with the start value, end value and number of increments.
Histogram(Salary, scale.x=c(30000,130000,5), scale.y=c(0,9.5,5))
The discrete, qualitative scale is a little darker and richer than before.
BarChart(Dept, fill="colors", color="off")
Can cutomize with speciied values of chroma (saturation) and luminace (brightness), here increasing chroma to 88 from its default value of 70 and decreasing luminance to 40 from its default value of 55.
BarChart(Dept, fill=getColors("colors", c=88, l=40), color="off")
More color options for progressive color continuums (more appropriate for an ordered scale). The full set of pre-defined color scales: “gray”, “blues”, “reds”, “greens”, “olives”, “turquoises”, “aquas”, and “purples”.
BarChart(Dept, fill="aquas", color="off")