Plotting with ggplot2: “Error: Discrete value supplied to continuous scale” on categorical y-axis

后端 未结 3 638
一生所求
一生所求 2020-11-29 04:26

The plotting code below gives Error: Discrete value supplied to continuous scale

What\'s wrong with this code? It works fine until I try to change the s

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 04:54

    As mentioned in the comments, there cannot be a continuous scale on variable of the factor type. You could change the factor to numeric as follows, just after you define the meltDF variable.

    meltDF$variable=as.numeric(levels(meltDF$variable))[meltDF$variable]
    

    Then, execute the ggplot command

      ggplot(meltDF[meltDF$value == 1,]) + geom_point(aes(x = MW, y =   variable)) +
         scale_x_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200)) +
         scale_y_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200))
    

    And you will have your chart.

    Hope this helps

提交回复
热议问题