在 R 中制作列的箱线图
Make boxplots of columns in R
我是 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')
我尝试了很多次,但我没有成功地为所有行制作箱线图。有人可以帮我吗?
正如@blondeclover 在评论中所说,boxplot()
应该可以很好地为每一列绘制箱线图。
如果您想要的是每个 行 的箱线图,那么实际上您当前的行需要是您的列。如果需要这样做,可以在绘图前转置数据框:
SUS.new <- as.data.frame(t(SUS))
boxplot(SUS.new)
您也可以使用 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))
我是 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')
我尝试了很多次,但我没有成功地为所有行制作箱线图。有人可以帮我吗?
正如@blondeclover 在评论中所说,boxplot()
应该可以很好地为每一列绘制箱线图。
如果您想要的是每个 行 的箱线图,那么实际上您当前的行需要是您的列。如果需要这样做,可以在绘图前转置数据框:
SUS.new <- as.data.frame(t(SUS))
boxplot(SUS.new)
您也可以使用 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))