Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中多标签数据的并排箱线图?_R_Plot_Boxplot_Exploratory Data Analysis - Fatal编程技术网

R中多标签数据的并排箱线图?

R中多标签数据的并排箱线图?,r,plot,boxplot,exploratory-data-analysis,R,Plot,Boxplot,Exploratory Data Analysis,我正在对goodreads\u score和三个布尔自变量之间的关系进行探索性的数据分析:虚构,畅销书,以及英语 set.seed(1) N <- 100 p <- rep(0.5, N) id <- c(1, N) fiction <- factor(rbinom(length(p), 1, p)) best_seller <- factor(rbinom(length(p), 1, p)) english <- factor(rbinom(length(p

我正在对
goodreads\u score
和三个布尔自变量之间的关系进行探索性的数据分析:
虚构
畅销书
,以及
英语

set.seed(1)
N <- 100
p <- rep(0.5, N)
id <- c(1, N)
fiction <- factor(rbinom(length(p), 1, p))
best_seller <- factor(rbinom(length(p), 1, p))
english <- factor(rbinom(length(p), 1, p))
goodreads_score <- runif(100, 0, 5) 

df <- data.frame(id, fiction, best_seller, english, goodreads_score)


我想知道是否可以将所有三个标签放在一个绘图中(有三个并排组)?

这可能满足您的需要:

df2 <- tidyr::gather(df, key = category, value = value, 
                     fiction:english, factor_key = TRUE )

ggplot(df2, aes(x=value, y=goodreads_score)) + 
  geom_boxplot(colour = "#3366FF", outlier.shape = NA) + 
  geom_jitter(position=position_jitter(width=.1, height=0.1)) +
  facet_wrap(~category, scale="free")
df2
df2 <- tidyr::gather(df, key = category, value = value, 
                     fiction:english, factor_key = TRUE )

ggplot(df2, aes(x=value, y=goodreads_score)) + 
  geom_boxplot(colour = "#3366FF", outlier.shape = NA) + 
  geom_jitter(position=position_jitter(width=.1, height=0.1)) +
  facet_wrap(~category, scale="free")
df2 <- tidyr::gather(df, key = category, value = value, 
                     fiction:english, factor_key = TRUE )

df2$cat_value <- paste0(df2$category,":",df2$value)
df2$cat_value <- factor(df2$cat_value , 
                        levels=c("fiction:0", "best_seller:0", "english:0",
                                 "fiction:1", "best_seller:1", "english:1"))

ggplot(df2, aes(x=cat_value, y=goodreads_score)) + 
  geom_boxplot(colour = "#3366FF", outlier.shape = NA) + 
  geom_jitter(position=position_jitter(width=.1, height=0.1)) +
  geom_vline(xintercept = 3.5, color = "red", linetype = "dashed", size = 1.4)