R 以一个变量作为参考对x轴上的数据进行排序
你好,我想这一定是件蠢事,但我被卡住了 我有5个参与者和两个任务R 以一个变量作为参考对x轴上的数据进行排序,r,sorting,ggplot2,R,Sorting,Ggplot2,你好,我想这一定是件蠢事,但我被卡住了 我有5个参与者和两个任务 participant<-1:5 scoreA<- c(20, 18, 19, 15,16) scoreB<- c(4, 2, 6, 1,3) 参与者你想要这样的东西吗 # Convert participant to a factor, with order given by the scoreA variable # from your "total" data frame totalM$participa
participant<-1:5
scoreA<- c(20, 18, 19, 15,16)
scoreB<- c(4, 2, 6, 1,3)
参与者你想要这样的东西吗
# Convert participant to a factor, with order given by the scoreA variable
# from your "total" data frame
totalM$participant <- factor(totalM$participant,
levels=arrange(total, scoreA)$participant)
# Plot!
ggplot(totalM, aes(participant, value, shape= variable, linetype=variable)) +
geom_point(size=5)+
geom_line(aes(x=as.numeric(participant)), size=1)
# Note the last geom, I modified the aes
#将参与者转换为因子,其顺序由scoreA变量给出
#从“总体”数据框
totalM$participant您想要这样的东西吗
# Convert participant to a factor, with order given by the scoreA variable
# from your "total" data frame
totalM$participant <- factor(totalM$participant,
levels=arrange(total, scoreA)$participant)
# Plot!
ggplot(totalM, aes(participant, value, shape= variable, linetype=variable)) +
geom_point(size=5)+
geom_line(aes(x=as.numeric(participant)), size=1)
# Note the last geom, I modified the aes
#将参与者转换为因子,其顺序由scoreA变量给出
#从“总体”数据框
totalM$participant我得到了一个好看的情节。你想让图表既向上又向右吗?在这种情况下,您需要添加total$participant,因为我得到了一个漂亮的绘图。你想让图表既向上又向右吗?在这种情况下,您需要添加工作完美的total$participant。谢谢,我是。作为荣誉,我认为这会更简单。但是,这肯定会使工作成功。@ajestudillo。如果答案是你想要的,别忘了把它标记为已接受。@ajestudillo一开始有点麻烦,但它是有意义的。您的participant
变量被解释为一个数字量,因此ggplot
自然使用一个连续的x刻度,因此是原始顺序。participant
数字实际上是一个分类变量,因为它代表一个人(我假设),默认情况下它按字母顺序排列。您只需手动设置订单,瞧。NB:需要使用plyr
包来使用arrange
,这样才能完美地工作。谢谢,我是。作为荣誉,我认为这会更简单。但是,这肯定会使工作成功。@ajestudillo。如果答案是你想要的,别忘了把它标记为已接受。@ajestudillo一开始有点麻烦,但它是有意义的。您的participant
变量被解释为一个数字量,因此ggplot
自然使用一个连续的x刻度,因此是原始顺序。participant
数字实际上是一个分类变量,因为它代表一个人(我假设),默认情况下它按字母顺序排列。您只需手动设置订单,瞧。NB:需要plyr
包来使用arrange
# Convert participant to a factor, with order given by the scoreA variable
# from your "total" data frame
totalM$participant <- factor(totalM$participant,
levels=arrange(total, scoreA)$participant)
# Plot!
ggplot(totalM, aes(participant, value, shape= variable, linetype=variable)) +
geom_point(size=5)+
geom_line(aes(x=as.numeric(participant)), size=1)
# Note the last geom, I modified the aes