[英]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: 我是R的初学者,并且对在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')
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. 就像@blondeclover在评论中说的那样,boxplot
boxplot()
应该可以很好地处理每一列的boxplot。
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
您也可以使用
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.