R 如何使用子集值和同一绘图上的所有值制作箱线图?
我正在使用基本R图 我想创建一个包含子集值和同一绘图上所有值的箱线图。关键是它必须在基本R图中R 如何使用子集值和同一绘图上的所有值制作箱线图?,r,plot,boxplot,R,Plot,Boxplot,我正在使用基本R图 我想创建一个包含子集值和同一绘图上所有值的箱线图。关键是它必须在基本R图中 Party <- rep(c("Rep", "Dem", "Ind"), 50) Values <- sample(1:100, size = length(Party), replace = T) hw <- data.frame(Party, Values) #Plot 1 boxplot(hw$Values, col=c("green"),
Party <- rep(c("Rep", "Dem", "Ind"), 50)
Values <- sample(1:100, size = length(Party), replace = T)
hw <- data.frame(Party, Values)
#Plot 1
boxplot(hw$Values,
col=c("green"),
xlab = "All Respondents")
#Plot 2
boxplot(hw$Values~hw$Party,
col=c("blue", "purple", "red"),
xlab = "Partisan Respondents")
Party这是一种将所有值添加到组中的简单方法
library(dplyr) # edited line
hw2 <- hw %>%
bind_rows(hw %>% mutate(Party = "ALL"))
boxplot(Values ~ Party, data = hw2,
col = c("gray60", "blue", "purple", "red"),
xlab = "Partisan Respondents")
library(dplyr)#编辑行
hw2%
绑定行(hw%>%mutate(Party=“ALL”))
箱线图(数值~Party,数据=hw2,
col=c(“灰色60”、“蓝色”、“紫色”、“红色”),
xlab=“党派受访者”)
library(dplyr),对吗?万分感谢!我感谢你的帮助!是的,很抱歉我不见了。