在R中运行ggscatter函数时出错

时间:2018-08-01 11:36:09

标签: r syntax-error scatter-plot

在运行散点图(ggscatter)时,系统会引发以下错误:

  

[。data.frame(data,,x)中的错误:未定义的列已选中

代码如下:

mydata<-data.frame("eng_score" = 1:99, "53_target_pre_mover_2_0_model" = 1:99)

library("ggpubr")
ggscatter(mydata,y = "eng_score"  , x = "`53_target_pre_mover_2_0_model`",  
      add = "reg.line", conf.int = TRUE, 
      cor.coef = TRUE, cor.method = "pearson",
      xlab = "Likely to move", ylab = "Engagement score")

感谢帮助!

1 个答案:

答案 0 :(得分:0)

使用时

mydata<-data.frame("eng_score" = 1:99, "53_target_pre_mover_2_0_model" = 1:99)

R不喜欢以数字开头的同名,因此,如果使用head(mydata),则会看到名称

  

53_target_pre_mover_2_0_model

更改为

  

X53_target_pre_mover_2_0_model

1)您可以在散点图中进行更改:

mydata<-data.frame("eng_score" = 1:99, "53_target_pre_mover_2_0_model" = 1:99)


library(ggpubr)
ggscatter(mydata,y = "eng_score"  , x = "X53_target_pre_mover_2_0_model",  
         add = "reg.line", conf.int = TRUE, 
         cor.coef = TRUE, cor.method = "pearson",
         xlab = "Likely to move", ylab = "Engagement score")

2)您停止在同名中产生X

您可以更改data.frame函数,而不用参数check.names=F来检查数字的姓氏:

mydata<-data.frame("eng_score" = 1:99, "53_target_pre_mover_2_0_model" = 1:99, check.names=F)