Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.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 x轴上多变量的散点图_R_Scatter Plot_Categorical Data - Fatal编程技术网

R x轴上多变量的散点图

R x轴上多变量的散点图,r,scatter-plot,categorical-data,R,Scatter Plot,Categorical Data,我想为不同列中定义的多个变量创建散点图。 样本输入: df=structure(list(section = structure(1:6, .Label = c("a", "b", "c", "d", "e", "f"), class = "factor"), level = c(0L, 1L, 2L, 1L, 2L, 0L), math.av = c(83L, 67L, 76L, 56L, 72L, 76L), science.av = c(75L, 76L, 82L, 72L, 82L

我想为不同列中定义的多个变量创建散点图。 样本输入:

df=structure(list(section = structure(1:6, .Label = c("a", "b", 
"c", "d", "e", "f"), class = "factor"), level = c(0L, 1L, 2L, 
1L, 2L, 0L), math.av = c(83L, 67L, 76L, 56L, 72L, 76L), science.av = c(75L, 
76L, 82L, 72L, 82L, 68L), language.av = c(80L, 75L, 80L, 73L, 
85L, 70L)), class = "data.frame", row.names = c(NA, -6L))
我希望x轴被划分为3个不同的主题列,y轴代表它们的不同值


我必须用另一列作为指标将它们按颜色分组,在这种情况下,根据级别

这里是一种使用
dplyr
ggplot2
的方法

首先,我们需要将数据转向长数据,而不是宽数据

library(dplyr)
library(tidyr)
long_df <- df %>% pivot_longer(-c(section,level))

数据

df <- structure(list(section = structure(1:6, .Label = c("a", "b", 
"c", "d", "e", "f"), class = "factor"), level = c(0L, 1L, 2L, 
1L, 2L, 0L), math.av = c(83L, 67L, 76L, 56L, 72L, 76L), science.av = c(75L, 
76L, 82L, 72L, 82L, 68L), language.av = c(80L, 75L, 80L, 73L, 
85L, 70L)), class = "data.frame", row.names = c(NA, -6L))

df请提供一个最简单的例子。另外,考虑使用facetting,使其更少confusing@FrancescoGrossetti更新了我的问题
df <- structure(list(section = structure(1:6, .Label = c("a", "b", 
"c", "d", "e", "f"), class = "factor"), level = c(0L, 1L, 2L, 
1L, 2L, 0L), math.av = c(83L, 67L, 76L, 56L, 72L, 76L), science.av = c(75L, 
76L, 82L, 72L, 82L, 68L), language.av = c(80L, 75L, 80L, 73L, 
85L, 70L)), class = "data.frame", row.names = c(NA, -6L))