简体   繁体   中英

Make boxplots of columns in R

I am a beginner in R, and have a question about making boxplots of columns in R. I just made a dataframe:

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')

I tried a number of times, but I did not succeed in making boxplots for all rows. Someone who can help me out here?

As @blondeclover says in the comment, boxplot() should work fine for doing a boxplot of each column.

If what you want is a boxplot for each row , then actually your current rows need to be your columns. If you need to do this, you can transpose the data frame before plotting:

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

You can do it as well using 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))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM