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

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


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


if x is numeric, then add scale_x_continuous(); if x is character/factor, then add scale_x_discrete(). This might solve your problem.


In my case, you need to convert the column(you think this column is numeric, but actually not) to numeric

geom_segment(data=tmpp,    aes(x=start_pos,    y=lib.complexity,    xend=end_pos,    yend=lib.complexity))# to geom_segment(data=tmpp,    aes(x=as.numeric(start_pos),    y=as.numeric(lib.complexity),    xend=as.numeric(end_pos),    yend=as.numeric(lib.complexity)))