x轴上多个变量的散点图

问题描述 投票:0回答:1

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

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轴划分为对象的4个不同列中的每个列,并将y轴表示为它们的不同值。

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

r scatter-plot categorical-data
1个回答
1
投票

这里是使用ggplot2的方法。

data <- data.frame(subject = rep(c("subject1","subject2","subject3","subject4"),each=10),value = c(runif(20,50,100),runif(20,70,120)), indicator = rep(c("A","B"),each = 20))

library(ggplot2)
ggplot(data, aes(x=as.factor(subject),y=value,fill=indicator)) + geom_dotplot(binaxis='y')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.