Learn R Programming

ez (version 1.2)

ezPlot: Function to plot data from a factorial experiment

Description

This function provides easy visualization of any given user-requested effect from factorial experiments, including purely within-Ss designs (a.k.a. "repeated measures"), purely between-Ss designs, and mixed within-and-between-Ss designs. By default, Fisher's Least Significant Difference is computed to provide error bars that facilitate visual post-hoc multiple comparisons (see Warning section below).

Usage

ezPlot(
	data
	, dv
	, sid
	, within = NULL
	, between = NULL
	, x
	, do_lines = TRUE
	, do_bars = TRUE
	, bar_width = NULL
	, bar_size = NULL
	, split = NULL
	, row = NULL
	, col = NULL
	, to_numeric = NULL
	, x_lab = NULL
	, y_lab = NULL
	, split_lab = NULL
)

Arguments

data
Data frame containing the data to be analyzed.
dv
.() object specifying the column in data that contains the dependent variable. Values in this column should be of the numeric class.
sid
.() object specifying the column in data that contains the variable specifying the case/Ss identifier. Values in this column will be converted to factor class if necessary.
within
Optional .() object specifying the column(s) in data that contains independent variables that are manipulated within-Ss. Values in this column will be converted to factor class if necessary.
between
Optional .() object specifying the column(s) in data that contains independent variables that are manipulated between-Ss. Values in this column will be converted to factor class if necessary.
x
.() object specifying the variable to plot on the x-axis.
do_lines
Logical. If TRUE, lines will be plotted connecting groups of points.
do_bars
Logical. If TRUE, error bars will be plotted.
bar_width
Optional numeric value specifying custom widths for the error bar hat.
bar_size
Optional numeric value or vector specifying custom size of the error bars.
split
Optional .() object specifying a variable by which to split the data into different shapes/colors (and line types, if do_lines==TRUE).
row
Optional .() object specifying a variable by which to split the data into rows.
col
Optional .() object specifying a variable by which to split the data into columns.
to_numeric
Optional .() object specifying any variables that need to be converted to the numeric class before plotting.
x_lab
Optional character string specifying the x-axis label.
y_lab
Optional character string specifying the y-axis label.
split_lab
Optional character string specifying the key label.

Value

  • A printable/modifiable ggplot2 object.

Warning

The default error bars are Fisher's Least Significant Difference for the plotted effect, facilitating visual post-hoc multiple comparisons. Note however that in the context of mixed within-and-between-Ss designs, these bars can only be used for within-Ss comparisons.

Details

While within and between are both optional, at least one column of data must be provided to either within or between. Any numeric or character variables in data that are specified as either sid, within or between will be converted to a factor with a warning.

See Also

ezANOVA, ezPerm, ezStats

Examples

Run this code
#Read in the ANT data (see ?ANT).
data(ANT)

#Show summaries of the ANT data.
head(ANT)
str(ANT)
summary(ANT)

#Compute some useful statistics per cell.
cell_stats = ddply(
	.data = ANT
	, .variables = .( sid , group , cue , flanker )
	, .fun <- function(x){
		#Compute error rate as percent.
		error_rate = (1-mean(x$acc))*100
		#Compute mean RT (only accurate trials).
		mean_rt = mean(x$rt[x$acc==1])
		#Compute SD RT (only accurate trials).
		sd_rt = sd(x$rt[x$acc==1])
		return(c(error_rate=error_rate,mean_rt=mean_rt,sd_rt=sd_rt))
	}
)

#Run an ANOVA on the mean_rt data.
mean_rt_anova = ezANOVA(
	data = cell_stats
	, dv = .(mean_rt)
	, sid = .(sid)
	, within = .(cue,flanker)
	, between = .(group)
)

#Show the ANOVA & assumption tests.
print(mean_rt_anova)

#Plot the main effect of group.
group_plot = ezPlot(
	data = cell_stats
	, dv = .(mean_rt)
	, sid = .(sid)
	, between = .(group)
	, x = .(group)
	, do_lines = FALSE
	, x_lab = 'Group'
	, y_lab = 'RT (ms)'
)

#Show the plot.
print(group_plot)

#Plot the cue*flanker interaction.
cue_by_flanker_plot = ezPlot(
	data = cell_stats
	, dv = .(mean_rt)
	, sid = .(sid)
	, within = .(cue,flanker)
	, x = .(flanker)
	, split = .(cue)
	, x_lab = 'Flanker'
	, y_lab = 'RT (ms)'
	, split_lab = 'Cue'
)

#Show the plot.
print(cue_by_flanker_plot)

#Plot the group*cue*flanker interaction.
group_by_cue_by_flanker_plot = ezPlot(
	data = cell_stats
	, dv = .(mean_rt)
	, sid = .(sid)
	, within = .(cue,flanker)
	, between = .(group)
	, x = .(flanker)
	, split = .(cue)
	, col = .(group)
	, x_lab = 'Flanker'
	, y_lab = 'RT (ms)'
	, split_lab = 'Cue'
)

#Show the plot.
print(group_by_cue_by_flanker_plot)

Run the code above in your browser using DataLab