How do I get discrete factor levels to be treated as continuous?

前端 未结 2 1972
鱼传尺愫
鱼传尺愫 2020-12-10 05:15

I have a data frame with columns initially labeled arbitrarily. Later on, I want to change these levels to numerical values. The following script illustrates the problem.

相关标签:
2条回答
  • 2020-12-10 05:53

    I think you can do this simply by transforming the variable to numeric:

    mdf$variable <- as.numeric(as.character(mdf$variable))
    
    g <- ggplot(mdf,aes(variable,value,group=variable,colour=t))
    g +
        geom_point() +
        #scale_x_continuous() +
        opts()
    
    0 讨论(0)
  • 2020-12-10 06:11

    You need to convert your factor into numeric:

    mdf$numVariable <- as.numeric(as.character(mdf$variable))
    
    g <- ggplot(mdf,aes(numVariable,value,group=variable,colour=t))
    g +
        geom_point() +
        #scale_x_continuous() +
        opts()
    

    Or just do the conversion in the call to ggplot:

    g <- ggplot(mdf,aes(as.numeric(as.character(variable)),value,group=variable,colour=t))
    
    0 讨论(0)
提交回复
热议问题