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

Posted Data+Science+Insight

tags:

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

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

#仿真数据

set.seed(123)
my_df1 <- data.frame(a=rnorm(100), b=runif(100), c=rep(1:10, 10))
my_df2 <- data.frame(a=rnorm(100), b=runif(100), c=factor(rep(LETTERS[1:5], 20)))

#发生错误:Error: Discrete value supplied to continuous scale

ggplot() +
  geom_point(data=my_df1, aes(x=a, y=b, color=c)) +
  geom_polygon(data=my_df2, aes(x=a, y=b, color=c), alpha=0.5)

#解决

使用fill参数;

ggplot() +
  geom_point(data=my_df1, aes(x=a, y=b, color=c)) +
  geom_polygon(data=my_df2, aes(x=a, y=b, fill=c), alpha=0.5)

参考:R 

以上是关于R语言问题解决: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语言ggplot2可视化时避免geom_bar对x轴进行排序实战:直接对因子变量进行提前排序后再进行可视化使用scale_x_discrete函数限定因子顺序

r discrete_time_ngarch.R

R语言学习笔记-Error in ts(x):对象不是矩阵问题解决