# # Beispiele zu Abschnitt I.2 # data(mtcars) help(mtcars) # # Anzahl an Beobachtungen length(mtcars[,1]) nrow(mtcars) # # absolute Häufgkeitstabelle der Zylinderanzahl # table(mtcars$cyl) # # # relative Häufgkeitstabelle der Zylinderanzahl # (in Prozent) # table(mtcars$cyl)/length(mtcars$cyl)*100 # # Liniendiagramme # plot( table(mtcars$cyl) ) plot( table(mtcars$cyl)/length(mtcars$cyl)*100 ) # # Säulendiagramme # barplot( table(mtcars$cyl) ) barplot( table(mtcars$cyl)/length(mtcars$cyl)*100 ) # # Kuchendiagramme # pie( table(mtcars$am) ) # 0=automatic; 1= manual # # # Kontingenztabelle und Mosaikplots library(pacman) p_load("tidyverse") p_load("ggmosaic") data(mpg) help(mpg) mpg_big_four <- mpg %>% filter(manufacturer %in% c("audi", "ford", "toyota", "volkswagen")) table( mpg_big_four$manufacturer, mpg_big_four$class ) mpg_big_four %>% ggplot() + geom_mosaic(aes(x = product(manufacturer, class), fill = manufacturer))