Plots kombinieren
In dieser Session wollen wir mehrere Plots in einem Bild kombinieren. Dazu laden wir zuerst unsere Daten in unsere R Session.
Daten <- read.csv("VITB12.csv", header = T, sep = ";")
Plots kombinieren
Um Plots zu kombinieren, benutzen wir die Kombination par(mfrow = c( , )). Hiermit können wir festlegen, in wievielen Zeilen und Spalten unsere Plots in dem neuen, kombinierten Bild vorliegen sollen. Innerhalb des Teils c( , ) geben wir als erste Zahl die Anzahl der Zeilen und als zweite Zahl die Anzahl der Spalten ein. Haben wir zum Beispiel 4 Plots, die wir in 2 Zeilen und 2 Spalten in einem Bild kombinieren möchten, so nutzen wir die Kombination par(mfrow = c(2,2)). Wir wollen uns nun 4 Plots erstellen, und diese in 2 Zeilen und 2 Spalten anordnen.
par(mfrow = c(2,2))
hist(Daten$Alter, main = "Altersverteilung der Messwerte",
col = "lightgreen",
xlab = "Alter in Jahren",
ylab = "Häufigkeit",
ylim = c(0,200),
xlim = c(0,100),
breaks = 50,
las = 1)
boxplot(Daten$Methylmalonsäure ~ Daten$Altersgruppe, main = "MMS in Abhängigkeit der Altersgruppe",
xlab = "Altersgruppe (Jahre)", ylab = "Methymalonsäure in nmol/l",
ylim = c(0,2000), col = "steelblue1", las = 1, notch = T)
boxplot(Daten$Holotranscobalamin ~ Daten$Altersgruppe, main = "HTC in Abhängigkeit der Altersgruppe",
xlab = "Altersgruppe (Jahre)", ylab = "Holotranscobalamin in pmol/l",
ylim = c(0,500), col = "violetred1", las = 1, notch = T)
boxplot(Daten$VitaminB12 ~ Daten$Altersgruppe, main = "Vitamin B12 in Abhängigkeit der Altersgruppe",
xlab = "Altersgruppe (Jahre)", ylab = "Vitamin B12 in pg/ml",
ylim = c(0,2000), col = "yellowgreen", las = 1, notch = T)
Ändern wir die Kombination auf 2 Zeilen und 3 Spalten erhlaten wir folgendes Bild.
par(mfrow = c(2,3))
hist(Daten$Alter, main = "Altersverteilung der Messwerte",
col = "lightgreen",
xlab = "Alter in Jahren",
ylab = "Häufigkeit",
ylim = c(0,200),
xlim = c(0,100),
breaks = 50,
las = 1)
boxplot(Daten$Methylmalonsäure ~ Daten$Altersgruppe, main = "MMS in Abhängigkeit der Altersgruppe",
xlab = "Altersgruppe (Jahre)", ylab = "Methymalonsäure in nmol/l",
ylim = c(0,2000), col = "steelblue1", las = 1, notch = T)
boxplot(Daten$Holotranscobalamin ~ Daten$Altersgruppe, main = "HTC in Abhängigkeit der Altersgruppe",
xlab = "Altersgruppe (Jahre)", ylab = "Holotranscobalamin in pmol/l",
ylim = c(0,500), col = "violetred1", las = 1, notch = T)
boxplot(Daten$VitaminB12 ~ Daten$Altersgruppe, main = "Vitamin B12 in Abhängigkeit der Altersgruppe",
xlab = "Altersgruppe (Jahre)", ylab = "Vitamin B12 in pg/ml",
ylim = c(0,2000), col = "yellowgreen", las = 1, notch = T)
So lassen sich vielfältige Plots in einem Bild kombinieren.