Error: Discrete value supplied to continuous scale

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error: Discrete value supplied to continuous scale相关的知识,希望对你有一定的参考价值。

Error: Discrete value supplied to continuous scale

目录

Error: Discrete value supplied to continuous scale

问题:

解决:

完整错误:


问题:

#y变量的数据类型为字符型(character),而ggplot2可视化需要的是数值啊,,,

#create data frame
df = data.frame(x = 1:12,
                y = rep(c('1', '2', '3', '4'), times=3))

#view data frame
df

library(ggplot2)

#attempt to create scatterplot with custom y-axis scale
ggplot(df, aes(x, y)) +
  geom_point() +
  scale_y_continuous(limits = c(0, 10))

解决:

#查看数据类型

#check class of y variable
class(df$y)

[1] "character"

#as.numeric进行转化(从字符型到数值型)

library(ggplot2) 

#convert y variable to numeric
df$y <- as.numeric(df$y)

#create scatterplot with custom y-axis scale
ggplot(df, aes(x, y)) +
  geom_point() +
  scale_y_continuous(limits = c(0, 10))

完整错误:

> library(ggplot2)

> #attempt to create scatterplot with custom y-axis scale
> ggplot(df, aes(x, y)) +
+     geom_point() +
+     scale_y_continuous(limits = c(0, 10))
Error: Discrete value supplied to continuous scale

以上是关于Error: Discrete value supplied to continuous scale的主要内容,如果未能解决你的问题,请参考以下文章

Error: Discrete value supplied to continuous scale

ERROR while rich displaying an object: Error: Continuous value supplied to discrete scale

R语言问题解决:Error: Discrete value supplied to continuous scale

Redis 数据类型归纳

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qvc66dfs/sup

如何使用 std::vector 初始化 boost::random::discrete_distribution?