2017-06-28 6 views
1

ich ein Anfänger in R bin und habe eine Frage zu Boxplots von Spalten in R. machen ich habe gerade einen Datenrahmen:Stellen Boxplots der Spalten in R

SUS <- data.frame(RD = c(4, 3, 4, 1, 2, 2, 4, 2, 4, 1), TK = c(4, 2, 4, 2, 2, 2, 4, 4, 3, 1), 
        WK = c(3, 2, 4, 1, 3, 3, 4, 2, 4, 2), NW = c(2, 2, 4, 2, NA, NA, 5, 1, 4, 2), 
        BW = c(3, 2, 4, 1, 4, 1, 4, 1, 5, 1), EK = c(2, 4, 3, 1, 2, 4, 2, 2, 4, 2), 
        AN = c(3, 2, 4, 2, 3, 3, 3, 2, 4, 2)) 


rownames(SUS) <- c('Pleasant to use', 'Unnecessary complex', 'Easy to use', 
        'Need help of a technical person', 'Different functions well integrated','Various function incohorent', 'Imagine that it is easy to learn', 
        'Difficult to use', 'Confident during use', 'Long duration untill I could work with it') 

ich einige Male versucht, aber ich ist es nicht gelungen, Boxplots für alle Zeilen zu erstellen. Jemand, der mir hier draußen helfen kann?

+0

Haben Sie eine boxplot für jede Spalte wollen oder für jede Reihe? Wenn Sie für jede Spalte einen Boxplot wünschen, sollte 'boxplot (SUS)' funktionieren. – blondeclover

Antwort

1

Sie es tun können, als auch mit tidyverse

library(tidyverse) 
SUS %>% 
    #create new column and save the row.names in it 
    mutate(variable = row.names(.)) %>% 
    #convert your data from wide to long 
    tidyr::gather("var", "value", 1:7) %>% 
    #plot it using ggplot2 
    ggplot(., aes(x = variable, y = value)) + 
    geom_boxplot()+ 
    theme(axis.text.x = element_text(angle=35,hjust=1)) 

enter image description here

1

Wie @blondeclover im Kommentar sagt, boxplot() sollte gut funktionieren für eine Boxplot jeder Spalte.

Wenn Sie wollen, ist ein Boxplot für jede Zeile, dann müssen Ihre aktuellen Zeilen tatsächlich Ihre Spalten sein. Wenn Sie dies tun, dann können Sie den Datenrahmen vor dem Plotten transponieren:

SUS.new <- as.data.frame(t(SUS)) 
boxplot(SUS.new) 
+0

Danke für die schnellen Antworten! Ich wollte tatsächlich für jede Zeile einen Boxplot machen. Ich habe mich gefragt, ob es auch möglich ist, dies mit ggplot zu tun? – ItK