Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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_Sorting_Ggplot2 - Fatal编程技术网

R 以一个变量作为参考对x轴上的数据进行排序

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

你好,我想这一定是件蠢事,但我被卡住了

我有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$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