Commit 7338fb48 authored by jbleher's avatar jbleher
Browse files

Stabdiagramm und ECDF hinzugefügt

parent b72584c5
Loading
Loading
Loading
Loading
+70 −0
Original line number Diff line number Diff line
rm(list = ls()) # Environment leeren


# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Einlesen der Urliste ----
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Einlesen der Daten
exampoints <- read.csv("01_data/points_only_sem_pt.csv",dec=",")

# Absolute Häufigkeiten
tblExampoints <- table(exampoints[,c("Punkte","Termin")])

# Beim Plotten der Häufigkeiten wird automatisch ein Stabdiagramm erstellt
png("points_only_sem_pt_stabdiagram.png", width = 1200, height = 800)
par(mar = c(6, 6, 4, 4)) 
plot(rownames(tblExampoints),tblExampoints[,"HT"],
     type="h",
     xlab = "Punkte", 
     ylab = "Häufigkeit", 
     col = "blue",
     cex.axis = 2,
     cex.lab = 2,
     cex.title = 2
     )
points(rownames(tblExampoints),tblExampoints[,"NT"],
       type = "h",
       col = "red", 
       cex = 0.5
)
legend("topright",
       legend = c("HT","NT"),
       col = c("blue","red"),
       lty = c(1,1),
       bty = "n",
       cex=2
)
dev.off()


# Relative Häufigkeiten
tblExampointsRel <- apply(tblExampoints,2,
                          function(x) x/sum(x))
plot(rownames(tblExampointsRel),tblExampointsRel[,"HT"],
     type="h",
     main = "Punkteverteilung", 
     xlab = "Punkte", 
     ylab = "relative Häufigkeit", 
     col = "blue"
)

points(rownames(tblExampointsRel),tblExampointsRel[,"NT"],
       type = "h",
       pch = 19, 
       col = "red"
)

# Empirische Verteilungsfunktion
png("points_only_sem_pt_ecdf.png", width = 1200, height = 800)
par(mar = c(6, 6, 4, 4)) 
plot(ecdf(as.numeric(exampoints$Punkte[exampoints$Termin == "HT"])),
     main="  ",
     cex.axis = 2,
     cex.lab = 2,
     )
plot(ecdf(as.numeric(exampoints$Punkte[exampoints$Termin == "NT"])),
     add = TRUE,
     col = "red"
)
dev.off()