ispired by:
age differences in reaction time local copy
age differences in p300 local copy
auditory and visual P300 local copy
task complexity and P300local copy
P300 at PZ
P300 latency ist höher für schwierigere Aufgaben (z.B. Wahrnehmungsdiskrimination)
Streudiagramme, auch gruppiert.
Eine kontinuierliche Variable kann über die Farbe oder Größe als “dritte Dimension” dienen.
# we take a look at the wide format
df.w <- read.delim("http://md.psych.bio.uni-goettingen.de/data/virt/rt_p3_w.txt")
head(df.w)
## subj gender age age.gr a.rt.sr a.rt.dr v.rt.sr v.rt.dr a.p3a.sr a.p3a.dr
## 1 1 f 17 15-25 235 403 275 446 7.40 6.64
## 2 2 f 22 15-25 230 396 273 437 7.21 6.35
## 3 3 m 18 15-25 219 358 262 397 6.16 5.79
## 4 4 m 21 15-25 215 352 254 390 7.57 7.02
## 5 5 f 46 45-55 270 444 307 484 5.60 4.86
## 6 6 f 53 45-55 266 437 307 479 3.68 3.27
## v.p3a.sr v.p3a.dr a.p3l.sr a.p3l.dr v.p3l.sr v.p3l.dr
## 1 10.47 9.92 385 420 422 459
## 2 10.04 9.62 394 437 430 465
## 3 8.96 8.36 382 417 420 452
## 4 10.21 9.59 399 439 440 473
## 5 8.34 7.75 440 502 476 534
## 6 6.80 6.05 449 505 484 537
# ... and read the modified long format of the same data
df <- read.delim("http://md.psych.bio.uni-goettingen.de/data/virt/rt_p3.txt")
head(df)
## subj_key subj gender age age.gr av complex rt p3a p3l
## 1 1_a_dr 1 f 17 15-25 a dr 403 6.64 420
## 2 1_a_sr 1 f 17 15-25 a sr 235 7.40 385
## 3 1_v_dr 1 f 17 15-25 v dr 446 9.92 459
## 4 1_v_sr 1 f 17 15-25 v sr 275 10.47 422
## 5 2_a_dr 2 f 22 15-25 a dr 396 6.35 437
## 6 2_a_sr 2 f 22 15-25 a sr 230 7.21 394
require(ggplot2)
## Loading required package: ggplot2
# a rough view at age effects
pplot <- ggplot(data=df, aes(x=age, y=rt))
pplot + geom_point()
# might be clearer by gender?
pplot + aes(color=gender) + geom_point()
# same with
pplot + geom_point(aes(color=gender))
# visual vs accoustic reaction times are supposed to have an effect
pplot + geom_point(aes(shape=gender, color=av))
# the various dependent variables correlated?
# P300 amplitude vs latency
ggplot(data=df, aes(x=p3a, y=p3l)) +
geom_point()
ggplot(data=df, aes(x=rt, y=p3a)) +
geom_point()
ggplot(data=df, aes(x=rt, y=p3l)) +
geom_point()
# a third pseudo dimension using colors
ggplot(data=df, aes(x=p3a, y=p3l, color=rt)) +
geom_point()
# a third pseudo dimension using size
ggplot(data=df, aes(x=p3a, y=p3l, size=rt)) +
geom_point()
# a third pseudo dimension using colors
ggplot(data=df, aes(x=p3a, y=p3l, color=rt, shape=complex)) +
geom_point()
schnell und flexibel deskriptive Visualisierungen
df <- read.delim("http://md.psych.bio.uni-goettingen.de/data/virt/rt_p3.txt")
require(ggplot2)
# bars
# geom_bar visualizes counts of factor classes
ggplot(df, aes(x=age.gr)) + geom_bar()
ggplot(df, aes(x=av)) + geom_bar()
# box plots summarize
ggplot(df, aes(x=age.gr, y=rt)) + geom_boxplot()
# ... even split by another factor
ggplot(df, aes(x=age.gr, y=rt, color=gender)) + geom_boxplot()
# ... or even split by a third factor
ggplot(df, aes(x=age.gr, y=rt, color=gender, shape=av)) + geom_boxplot()
# ... maybe better using facets
ggplot(df, aes(x=age.gr, y=rt, color=gender)) +
geom_boxplot() +
facet_wrap(~av)
ggplot(df, aes(x=age.gr, y=rt, color=av)) +
geom_boxplot() +
facet_wrap(~gender)
geom_bar()
hat count()
als voreingestellte Funktion, um den darzustellenden Wert zu berechnen. Wir können hier auch andere Werte durch die Säulen darstellen lassen.
df <- read.delim("http://md.psych.bio.uni-goettingen.de/data/virt/rt_p3.txt")
require(ggplot2)
#
ggplot(df, aes(age.gr, rt, color=age.gr)) +
geom_bar(stat = "summary_bin", fun.y = mean)
ggplot(df, aes(age.gr, rt, fill=age.gr)) +
geom_bar(stat = "summary_bin", fun.y = mean) +
facet_wrap(~av)
Linien dienen hauptsächlich für die Darstellung von Verläufen (Zeitreihen). Verläufe brauchen für x- und y-Achse Zahlenwerte (! factor).
Macht beim vorliegenden Datensatz wenig Sinn.
df <- read.delim("http://md.psych.bio.uni-goettingen.de/data/virt/rt_p3.txt")
df$subj <- as.factor(df$subj)
# we create a fake time course over conditions to be able to show something using individual lines
df$t.n <- as.numeric(df$complex) + as.numeric(df$av) *2
require(ggplot2)
# individual curves
ggplot(data=df, aes(x=t.n, y=rt, group=subj, color=subj)) +
#aes(stat='identity') +
#geom_line(aes(group=subj)) +
geom_line() +
geom_point()
ggplot(data=df, aes(x=complex, y=rt, group=subj, color=subj)) +
#aes(stat='identity') +
#geom_line(aes(group=subj)) +
geom_line() +
geom_point() +
facet_wrap(~av)
Spezielle Funktionen können die voreingestellte Aggregierung der Daten überschreiben
Geoms haben bestimmte Parameter, die wir überschreiben können, d.h., wir können eine Funktion übergeben, die die Werte für die Paramter berechnet. Dies ändert das Verhalten des Geom. Hier sehen wir das für das Geom pointrange und für das Geom line
Wir überschreiben ein Default-Verhalten für einen Parameter, indem wir in stat_summary()
für alle Paramter, die wir überschreiben wollen, eine Funktion definieren, die genauso heißt, wie der Parameter aber vorne dran ein “fun.” stehen hat. Z. B. kennt das Geom pointrange()
die Paramter “ymin” und “ymax”, die obligatorisch sind. Wir überschreiben diese Parameter durch das Definieren einer Funktion “fun.ymin” für den Parameter “ymin” bzw. “fun.ymax” für den Parameter “ymax”
df <- read.delim("http://md.psych.bio.uni-goettingen.de/data/virt/rt_p3.txt")
require(ggplot2)
ggplot(df, aes(x = age.gr, y = rt, colour = complex, group = complex)) +
stat_summary(fun.y = mean,
fun.ymin = function(x) mean(x) - sd(x),
fun.ymax = function(x) mean(x) + sd(x),
geom = "pointrange") +
stat_summary(fun.y = mean,
geom = "line") +
facet_wrap( ~ av)