View source: R/UBStats_Main_Visible_ALL_202406.R
distr.plot.xy | R Documentation |
distr.plot.xy()
generates plots of a bivariate distribution.
distr.plot.xy(
x,
y,
plot.type,
bar.type = "stacked",
freq = "counts",
freq.type = "joint",
breaks.x,
breaks.y,
interval.x = FALSE,
interval.y = FALSE,
bw = FALSE,
color = NULL,
var.c,
breaks.c,
interval.c = FALSE,
adj.breaks = TRUE,
fitline = FALSE,
legend = TRUE,
use.scientific = FALSE,
data,
...
)
x , y |
Unquoted strings identifying the variables whose
distribution has to be graphically displayed. |
plot.type |
A single character specifying the type of plot to build.
Allowed options are |
bar.type |
A single character indicating whether in a bar plot
stacked ( |
freq |
A single character specifying the frequencies
to be displayed when a bar plot is requested ( |
freq.type |
A single character specifying the type of
frequencies to be displayed when a bar plot is requested
( |
breaks.x , breaks.y |
Allow to classify the variables |
interval.x , interval.y |
Logical values indicating whether
|
bw |
Logical value indicating whether plots should be colored
in scale of greys ( |
color |
Optional string vector allowing to specify colors
to use in the plot rather than a standard palette
( |
var.c |
An optional unquoted string identifying one variable
used to color points in a scatter plot ( |
breaks.c |
Allows to classify the variable |
interval.c |
Logical value indicating whether |
adj.breaks |
Logical value indicating whether the endpoints of
intervals of a numerical variable ( |
fitline |
Logical value indicating whether the line of best fit (also
called trend line or regression line) should be added to a scatter plot
( |
legend |
Logical value indicating whether a legend should be displayed
in the plot ( |
use.scientific |
Logical value indicating whether numbers on
axes should be displayed using scientific notation
( |
data |
An optional data frame containing |
... |
Additional arguments to be passed to low level functions. |
No return value, called for side effects.
Raffaella Piccarreta raffaella.piccarreta@unibocconi.it
distr.table.xy()
for tabulating a bivariate
distribution.
distr.table.x()
for tabulating a univariate
distribution.
distr.plot.x()
for plotting a univariate
distribution.
data(MktDATA, package = "UBStats")
# Bivariate bar plots
# - Two discrete variables (factor or vector with few levels)
# Joint counts
distr.plot.xy(CustClass, Children,plot.type = "bars",
freq = "Counts", freq.type = "joint",
data = MktDATA)
# - Two discrete variables (factor or vector with few levels)
# Joint percentages, side-by-side bars
# User-defined colors
distr.plot.xy(Children,CustClass, plot.type = "bars",
bar.type = "beside",
freq = "percent", freq.type = "joint",
color = c("red","gold","green","forestgreen"),
data = MktDATA)
# - One numeric variable classified into intervals
# and one variable measured in classes
# Conditional percentages of x|y
distr.plot.xy(TotPurch, Income, plot.type = "bars",
freq = "percent",freq.type = "x|y",
breaks.x = c(0,5,10,15,20,35),
interval.y = TRUE, data = MktDATA)
# Conditional percentages of y|x
distr.plot.xy(TotPurch, Income, plot.type = "bars",
freq = "percent",freq.type = "y|x",
breaks.x = c(0,5,10,15,20,35),
interval.y = TRUE, data = MktDATA)
# Side-by-side boxplots
# - A continuous variable conditioned to a factor,
# a character, or a classified variable
# The distributions of the numeric variable conditioned
# to the factor (or character) are displayed
distr.plot.xy(x = AOV, y = Education, plot.type = "boxplot",
data = MktDATA)
distr.plot.xy(x = Income.S, y = AOV, plot.type = "boxplot",
interval.x = TRUE, data = MktDATA)
distr.plot.xy(x = Baseline, y = TotPurch, plot.type = "boxplot",
breaks.y = c(0,5,10,15,20,35),
data = MktDATA)
# - Two numerical variables. By default distributions
# of y|x are displayed unless differently
# specified in freq.type
distr.plot.xy(x = NPickUp_Purch, y = NWeb_Purch,
plot.type = "boxplot", data = MktDATA)
distr.plot.xy(x = NPickUp_Purch, y = NWeb_Purch,
plot.type = "boxplot",freq.type = "x|y",
data = MktDATA)
# Scatter plots
# - Two numerical variables: default options
distr.plot.xy(Baseline, TotVal, plot.type = "scatter",
fitline = TRUE, data = MktDATA)
# - Two numerical variables: colors based on discrete var
distr.plot.xy(Baseline, TotVal, plot.type = "scatter",
var.c = Marital_Status,
fitline = TRUE, data = MktDATA)
distr.plot.xy(Baseline, TotVal, plot.type = "scatter",
var.c = Income, interval.c = TRUE,
fitline = TRUE, data = MktDATA)
distr.plot.xy(Baseline, TotVal, plot.type = "scatter",
var.c = TotPurch, breaks.c = 10,
fitline = TRUE, data = MktDATA)
# - Two numerical variables: colors based
# on a continuous numerical variable
distr.plot.xy(Baseline, TotVal, plot.type = "scatter",
var.c = AOV, fitline = TRUE, data = MktDATA)
# - One numerical variable and one factor or character
distr.plot.xy(Baseline, Marital_Status, plot.type = "scatter",
fitline = TRUE, data = MktDATA)
distr.plot.xy(Income.S, Baseline, plot.type = "scatter",
interval.x = TRUE,
fitline = TRUE, data = MktDATA)
# color based on a third variable
distr.plot.xy(TotPurch, TotVal, plot.type = "scatter",
breaks.x = c(0,5,10,15,20,35),
var.c = AOV,
fitline = TRUE, data = MktDATA)
# - Two factors or character vectors: bubble plots
distr.plot.xy(Education, LikeMost, plot.type = "scatter",
data = MktDATA)
# - Two classified variables (i.e. not properly numerical):
# bubble plots, changed color
distr.plot.xy(Income.S, TotPurch, plot.type = "scatter",
interval.x = TRUE,
breaks.y = c(0,5,10,15,20,35),
color = "orchid", data = MktDATA)
# Arguments adj.breaks and use.scientific
# Variable with very wide ranges
LargeC<-MktDATA$AOV*5000000
LargeX<-MktDATA$Baseline*1000000
LargeY<-MktDATA$TotVal*1000000
# - Default: no scientific notation
distr.plot.xy(LargeX, LargeY, plot.type = "scatter",
var.c = LargeC, data = MktDATA)
distr.plot.xy(LargeX, LargeY, plot.type = "scatter",
breaks.x = 10, var.c = LargeC,
data = MktDATA)
# - Scientific notation for axes
distr.plot.xy(LargeX, LargeY, plot.type = "scatter",
breaks.x = 10, var.c = LargeC,
use.scientific = TRUE,
data = MktDATA)
# - Scientific notation for intervals' endpoints
distr.plot.xy(LargeX, LargeY, plot.type = "scatter",
breaks.x = 10, var.c = LargeC,
adj.breaks = FALSE,
data = MktDATA)
# - Scientific notation for intervals endpoints and axes
distr.plot.xy(LargeX, LargeY, plot.type = "scatter",
var.c = LargeC, fitline = TRUE,
adj.breaks = FALSE, use.scientific = TRUE,
data = MktDATA)
distr.plot.xy(LargeX, LargeY, plot.type = "scatter",
breaks.x = 10, var.c = LargeC,
adj.breaks = FALSE, use.scientific = TRUE,
data = MktDATA)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.