Movatterモバイル変換


[0]ホーム

URL:


Title:Letter Value 'Boxplots'
Version:0.2.2
Description:Implements the letter value 'boxplot' which extends the standard 'boxplot' to deal with both larger and smaller number of data points by dynamically selecting the appropriate number of letter values to display.
License:GPL-2 |GPL-3 [expanded from: GPL (≥ 2)]
Depends:R (≥ 2.14)
Imports:ggplot2 (≥ 3.3.0), grid, RColorBrewer, tibble
Encoding:UTF-8
LazyData:true
LazyDataCompression:xz
RoxygenNote:7.3.2.9000
URL:https://github.com/hadley/lvplot
BugReports:https://github.com/hadley/lvplot/issues
NeedsCompilation:no
Packaged:2025-09-03 19:47:28 UTC; hadleywickham
Author:Hadley Wickham [aut, cre], Heike Hofmann [aut]
Maintainer:Hadley Wickham <hadley@rstudio.com>
Repository:CRAN
Date/Publication:2025-09-03 20:10:02 UTC

lvplot: Letter Value 'Boxplots'

Description

Implements the letter value 'boxplot' which extends the standard 'boxplot' to deal with both larger and smaller number of data points by dynamically selecting the appropriate number of letter values to display.

Author(s)

Maintainer: Hadley Wickhamhadley@rstudio.com

Authors:

See Also

Useful links:


Side-by-side LV boxplots with base graphics

Description

An extension of standard boxplots which draws k letter statistics.Conventional boxplots (Tukey 1977) are useful displays for conveying roughinformation about the central 50% of the data and the extent of the data.

Usage

LVboxplot(x, ...)## S3 method for class 'formula'LVboxplot(  formula,  alpha = 0.95,  k = NULL,  perc = NULL,  horizontal = TRUE,  xlab = NULL,  ylab = NULL,  col = "grey30",  bg = "grey90",  width = 0.9,  width.method = "linear",  median.col = "grey10",  ...)## S3 method for class 'numeric'LVboxplot(  x,  alpha = 0.95,  k = NULL,  perc = NULL,  horizontal = TRUE,  xlab = NULL,  ylab = NULL,  col = "grey30",  bg = "grey90",  width = 0.9,  width.method = "linear",  median.col = "grey10",  ...)

Arguments

x

numeric vector of data

...

passed ontoplot

formula

a plotting formula of the formy ~ x, wherexis a string or factor. The values ofy will be split into groupsaccording to their values onx and separate letter value box plotsofy are drawn side by side in the same display.

alpha

if supplied, depth k is calculated such that (1-alpha)100intervals of an LV statistic do not extend intoneighboring LV statistics.

k

number of letter value statistics used

perc

if supplied, depth k is adjusted such thatperc percentoutliers are shown

horizontal

display horizontally (TRUE) or vertically (FALSE)

xlab

x axis label

ylab

y axis label

col

vector of colours to use

bg

background colour

width

maximum height/width of box

width.method

one of 'linear', 'height' or 'area'. Methods 'height' and 'area' ensure that these dimension are proportional to the number of observations within each box.

median.col

colour of the line for the median

Details

For moderate-sized data sets (n < 1000), detailed estimates of tailbehavior beyond the quartiles may not be trustworthy, so the informationprovided by boxplots is appropriately somewhat vague beyond the quartiles,and the expected number of “outliers” and “far-out” values for aGaussian sample of sizen is often less than 10 (Hoaglin, Iglewicz,and Tukey 1986). Large data sets (n \approx 10,000-100,000) affordmore precise estimates of quantiles in the tails beyond the quartiles andalso can be expected to present a large number of “outliers” (about0.4 + 0.007 n).

The letter-value box plot addresses both these shortcomings: it conveysmore detailed information in the tails using letter values, only out to thedepths where the letter values are reliable estimates of theircorresponding quantiles (corresponding to tail areas of roughly2^{-i}); “outliers” are defined as a function of the most extremeletter value shown. All aspects shown on the letter-value boxplot areactual observations, thus remaining faithful to the principles thatgoverned Tukey's original boxplot.

Examples

n <- 10oldpar <- par()par(mfrow=c(4,2), mar=c(3,3,3,3))for (i in 1:4) {  x <- rexp(10 ^ (i + 1))  boxplot(x, col = "grey", horizontal = TRUE)  title(paste("Exponential, n = ", length(x)))  LVboxplot(x, col = "grey", xlab = "")}par(mfrow=oldpar$mfrow, mar=oldpar$mar)with(ontime, LVboxplot(sqrt(TaxiIn + TaxiOut) ~ UniqueCarrier, horizontal=FALSE))

County demographics based on 1980 US Census

Description

County level statistics based on the 1980 US Census.

Usage

census

Format

A data frame with 10 variables

county

County name

FIPS

FIPS county code

Latitude,Longitude

Geographic location of county centers

JanTmp,JulTmp

(normalized) Temperatures in January & July

JanSun,JulSun

(normalized) Sunshine measurment in January & July

Elevtn

Elevation above sea level

totalpop

Population


Determine depth of letter values needed for n observations.

Description

Determine depth of letter values needed for n observations.

Usage

determineDepth(n, k = NULL, alpha = NULL, perc = NULL)

Arguments

n

number of observation to be shown in the LV boxplot

k

number of letter value statistics used

alpha

if supplied, depth k is calculated such that (1-alpha)100intervals of an LV statistic do not extend intoneighboring LV statistics.

perc

if supplied, depth k is adjusted such thatperc percentoutliers are shown

Details

Supply one ofk,alpha orperc.


Draw an LV plot.

Description

Draw an LV plot.

Usage

drawLVplot(  x,  y,  k,  out,  qu,  horizontal,  col,  border = "grey50",  width = 0.9,  width.method = "linear",  median.col,  ...)

Arguments

x

x positions

y

y positions

k

number of letter value statistics used

out

indices of outliers

qu

quantiles

horizontal

display horizontally (TRUE) or vertically (FALSE)

col

vector of colours to use

border

vector of colours to use

width

maximum height/width of box

width.method

one of 'linear', 'height' or 'area'. Methods 'height' and 'area' ensure that these dimension are proportional to the number of observations within each box.


Side-by-side LV boxplots with ggplot2.

Description

An extension of standard boxplots which draws k letter statistics.Conventional boxplots (Tukey 1977) are useful displays for conveying roughinformation about the central 50% of the data and the extent of the data.For moderate-sized data sets (n < 1000), detailed estimates of tailbehavior beyond the quartiles may not be trustworthy, so the informationprovided by boxplots is appropriately somewhat vague beyond the quartiles,and the expected number of “outliers” and “far-out” values for aGaussian sample of sizen is often less than 10 (Hoaglin, Iglewicz,and Tukey 1986). Large data sets (n \approx 10,000-100,000) affordmore precise estimates of quantiles in the tails beyond the quartiles andalso can be expected to present a large number of “outliers” (about0.4 + 0.007 n).The letter-value box plot addresses both these shortcomings: it conveysmore detailed information in the tails using letter values, only out to thedepths where the letter values are reliable estimates of theircorresponding quantiles (corresponding to tail areas of roughly2^{-i}); “outliers” are defined as a function of the most extremeletter value shown. All aspects shown on the letter-value boxplot areactual observations, thus remaining faithful to the principles thatgoverned Tukey's original boxplot.

Usage

geom_lv(  mapping = NULL,  data = NULL,  stat = "lv",  position = "dodge",  outlier.colour = "black",  outlier.shape = 19,  outlier.size = 1.5,  outlier.stroke = 0.5,  na.rm = TRUE,  varwidth = FALSE,  width.method = "linear",  show.legend = NA,  inherit.aes = TRUE,  ...)GeomLvscale_fill_lv(...)stat_lv(  mapping = NULL,  data = NULL,  geom = "lv",  position = "dodge",  na.rm = TRUE,  conf = 0.95,  percent = NULL,  k = NULL,  show.legend = NA,  inherit.aes = TRUE,  ...)StatLv

Arguments

mapping

Set of aesthetic mappings created byaes(). If specified andinherit.aes = TRUE (the default), it is combined with the default mappingat the top level of the plot. You must supplymapping if there is no plotmapping.

data

The data to be displayed in this layer. There are threeoptions:

IfNULL, the default, the data is inherited from the plotdata as specified in the call toggplot().

Adata.frame, or other object, will override the plotdata. All objects will be fortified to produce a data frame. Seefortify() for which variables will be created.

Afunction will be called with a single argument,the plot data. The return value must be adata.frame, andwill be used as the layer data. Afunction can be createdfrom aformula (e.g.~ head(.x, 10)).

position

A position adjustment to use on the data for this layer. Thiscan be used in various ways, including to prevent overplotting andimproving the display. Theposition argument accepts the following:

  • The result of calling a position function, such asposition_jitter().This method allows for passing extra arguments to the position.

  • A string naming the position adjustment. To give the position as astring, strip the function name of theposition_ prefix. For example,to useposition_jitter(), give the position as"jitter".

  • For more information and other ways to specify the position, see thelayer position documentation.

outlier.colour

Override aesthetics used for the outliers. Defaultscome fromgeom_point().

outlier.shape

Override aesthetics used for the outliers. Defaultscome fromgeom_point().

outlier.size

Override aesthetics used for the outliers. Defaultscome fromgeom_point().

outlier.stroke

Override aesthetics used for the outliers. Defaultscome fromgeom_point().

na.rm

IfFALSE (the default), removes missing values witha warning. IfTRUE silently removes missing values.

varwidth

ifFALSE (default) draw boxes that are the same size for each group. IfTRUE, boxes are drawn with widths proportional to thesquare-roots of the number of observations in the groups (possiblyweighted, using theweight aesthetic).

width.method

character, one of 'linear' (default), 'area', or 'height'. This parameterdetermines whether the width of the box for letter valueLV(i) should be proportional to i (linear), proportional to2^{-i} (height), or whether the area of the box should be proportional to2^{-i} (area).

show.legend

logical. Should this layer be included in the legends?NA, the default, includes if any aesthetics are mapped.FALSE never includes, andTRUE always includes.It can also be a named logical vector to finely select the aesthetics todisplay. To include legend keys for all levels, evenwhen no data exists, useTRUE. IfNA, all levels are shown in legend,but unobserved levels are omitted.

inherit.aes

IfFALSE, overrides the default aesthetics,rather than combining with them. This is most useful for helper functionsthat define both data and aesthetics and shouldn't inherit behaviour fromthe default plot specification.

...

Other arguments passed on tolayer()'sparams argument. Thesearguments broadly fall into one of 4 categories below. Notably, furtherarguments to theposition argument, or aesthetics that are requiredcannot be passed through.... Unknown arguments that are not partof the 4 categories below are ignored.

  • Static aesthetics that are not mapped to a scale, but are at a fixedvalue and apply to the layer as a whole. For example,colour = "red"orlinewidth = 3. The geom's documentation has anAestheticssection that lists the available options. The 'required' aestheticscannot be passed on to theparams. Please note that while passingunmapped aesthetics as vectors is technically possible, the order andrequired length is not guaranteed to be parallel to the input data.

  • When constructing a layer usinga⁠stat_*()⁠ function, the... argument can be used to pass onparameters to thegeom part of the layer. An example of this isstat_density(geom = "area", outline.type = "both"). The geom'sdocumentation lists which parameters it can accept.

  • Inversely, when constructing a layer using a⁠geom_*()⁠ function, the... argument can be used to pass on parametersto thestat part of the layer. An example of this isgeom_area(stat = "density", adjust = 0.5). The stat's documentationlists which parameters it can accept.

  • Thekey_glyph argument oflayer() may also be passed on through.... This can be one of the functions described askey glyphs, to change the display of the layer in the legend.

geom,stat

Use to override the default connection betweengeom_lv andstat_lv.

conf

confidence level

percent

numeric value: percent of data in outliers

k

number of letter values shown

Format

An object of classGeomLv (inherits fromGeom,ggproto,gg) of length 6.

An object of classStatLv (inherits fromStat,ggproto,gg) of length 5.

Computed/reported variables

k

Number of Letter Values used for the display

LV

Name of the Letter Value

width

width of the interquartile box

References

McGill, R., Tukey, J. W. and Larsen, W. A. (1978) Variations ofbox plots. The American Statistician 32, 12-16.

See Also

stat_quantile to view quantiles conditioned on acontinuous variable.

Examples

library(ggplot2)p <- ggplot(mpg, aes(class, hwy))p + geom_lv(aes(fill = after_stat(LV))) + scale_fill_brewer()p + geom_lv() + geom_jitter(width = 0.2)p + geom_lv(aes(fill = after_stat(LV))) + scale_fill_lv()# Outliersp + geom_lv(varwidth = TRUE, aes(fill = after_stat(LV))) + scale_fill_lv()p + geom_lv(fill = "grey80", colour = "black")p + geom_lv(outlier.colour = "red", outlier.shape = 1)# Plots are automatically dodged when any aesthetic is a factorp + geom_lv(aes(fill = drv))# varwidth adjusts the width of the boxes according to the number of observationsggplot(ontime, aes(UniqueCarrier, TaxiIn + TaxiOut)) +  geom_lv(aes(fill = after_stat(LV)), varwidth=TRUE) +  scale_fill_lv() +  scale_y_sqrt() +  theme_bw()ontime$DayOfWeek <- as.POSIXlt(ontime$FlightDate)$wdayggplot(ontime, aes(factor(DayOfWeek), TaxiIn + TaxiOut)) +  geom_lv(aes(fill = after_stat(LV))) +  scale_fill_lv() +  scale_y_sqrt() +  theme_bw()

Compute table of k letter values for vector x

Description

Compute table of k letter values for vector x

Usage

lvtable(x, k, alpha = 0.95)

Arguments

x

input numeric vector

k

number of letter values to compute

alpha

alpha-threshold for confidence level


Ontime Flight Data

Description

Data set detailing on-time performance of national US flights inJanuary 2015. This data is a subset of the data provided by the US Department ofTransportation. The full data as well as archived or more recent data is available for download fromhttp://www.transtats.bts.gov/DL_SelectFields.asp?Table_ID=236&DB_Short_Name=On-Time.

Usage

ontime

Format

A data frame consisting of the variables

FlightDate

a date variable of the day of the flight

UniqueCarrier

factor variable of the carrier (using the two letter abbreviation)

FlightNum

numeric variable of the flight number

CRSDepTime

scheduled departure time in hhmm format

DepTime

actual departure time in hhmm format

CRSArrTime

scheduled arrival time in hhmm format

ArrTime

actual arrival time in hhmm format

TaxiOut

numeric variable of the taxi out time in minutes

TaxiIn

numeric variable of the taxi in time in minutes

ArrDelay

Arrival delay, in Minutes

DepDelay

Departure delay, in Minutes

CarrierDelay

Carrier Delay, in Minutes

WeatherDelay

Weather Delay, in Minutes

NASDelay

National Air System Delay, in Minutes

SecurityDelay

Security Delay, in Minutes

LateAircraftDelay

Late Aircraft Delay, in Minutes

References

http://www.transtats.bts.gov/DL_SelectFields.asp?Table_ID=236&DB_Short_Name=On-Time

Examples

library(ggplot2)ggplot(ontime, aes(UniqueCarrier, TaxiIn + TaxiOut)) +  geom_lv(aes(fill = after_stat(LV))) +  scale_fill_lv() +  scale_y_sqrt() +  theme_bw()

[8]ページ先頭

©2009-2025 Movatter.jp