The “discrete value gave to continuous scale” error post is one that outcomes from a straightforward coding mistake. The is among the easiest mistakes come find and also correct. Unfortunately, it is also simple mistake to make in the an initial place. However, once you recognize it the is also easy to avoid.

You are watching: Error: discrete value supplied to continuous scale


Special note: every the code instances used in this short article require the ggplot2 package. If you execute not have actually it set up you have the right to use the complying with code to download it.
install.packages("ggplot2")Once it is mounted you will must run the adhering to code prior to running any type of projects that usage the ggplot2 package.library("ggplot2")

The situations of this error.

The “discrete value provided to consistent scale” article occurs when using the ggplot() role along through the scale__continuous()scale duty to point out a particular scale because that a graph.# r error discrete value gave to consistent scale> a = data.frame(x = 1:10, y = c("cat", "dog", "bat", "cow", "rat"))> ggplot(a, aes(x, y)) + geom_point()In this example of the straightforward usage that ggplot(), the scale duty is no used. However, the does develop a successful graph that the data frame. Getting this post requires consisting of the scale role and doing for this reason incorrectly. That turns out to it is in the an essential to addressing the constant variable problem and also that is making use of the scale role correctly.

What is resulting in this error?

The “discrete value supplied to consistent scale” blog post is resulted in by erroneous usage of the scale role along through ggplot().
# discrete value offered to continuous scale r error> a = data.frame(x = 1:10, y = c("cat", "dog", "bat", "cow", "rat"))> ggplot(a, aes(x, y)) + geom_point() + scale_y_continuous(limits = c(0, 15))Error: Discrete value offered to constant scaleThe mistake in this example that leader to the error post is do the efforts to produce a consistent scale for the “y” axis. The problem is the the “y” vector is a discrete variable consisting the words, i.e. A character vector or categorical variable, not a numeric vector, which would certainly create continuous data. This means that you space trying to create a constant value for a discrete worth axis. The does no work causing our message.

How to deal with this error.

See more: Watch Game Of Thrones Season 8 Episode 3 123Movies, Game Of Thrones Season 8 Episode 3 Hindi

The “discrete value provided to continuous scale” message can be fixed however making certain that at least one that the place scales in the data framework is a consistent value fairly than a discrete scale and applying the scale function to that character vector to make it a numeric vector.# discrete value supplied to continuous scale solution> a = data.frame(x = 1:10, y = c("cat", "dog", "bat", "cow", "rat"))> ggplot(a, aes(x, y)) + geom_point() + scale_x_continuous(limits = c(0, 15))As you can see native this instance using “x” instead of “y” in the scale duty fixes the problem by supplying a numeric value list rather of characters. This aspect makes all the difference.# discrete value continuous scale r solution> a = data.frame(x = 1:10, y = c(1:5))> ggplot(a, aes(x, y)) + geom_point() + scale_y_continuous(limits = c(0, 7))The other option as seen over is to turn “y” right into a numeric list as depicted above. The one trouble with this equipment is that the dataset graph, scatter plot, crate plot, or bar chart is losing some of its meaning. This is due to the fact that the model no longer has actually the categorical change labels the it previously did.The “discrete value gave to constant scale” error post is an ext of a boy nuisance 보다 a severe problem. It is just a matter of making use of the not correct vector from the data frame. Correcting the one continuous data wrong in your plotting code solves the difficulty in a basic and straightforward manner.R Error: discrete value gave to consistent scale
Ezoicreport this ad
Resources to aid you leveling data repertoire and analysis using R. Automate all the things!

Web Scraping with R (Examples)Monte Carlo Simulation in RConnecting R come DatabasesAnimation & GraphicsManipulating Data FramesMatrix Algebra OperationsSamplingStatisticsCommon Errors
Ezoicreport this ad

Categories

ArticlesBook reviewsFeatured R consultantsHelpPython HelpR consultantsR job listingsR tasks listservSite news