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

Posted Data+Science+Insight

tags:

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

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

目录

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

问题:

解决

完整错误:

#参考示例mtcars


问题:

Pre0 <-rms::Predict(fit,Hb,fun=exp,type="predictions",ref.zero=TRUE,conf.int = 0.95,digits=2);
##其中fun是转化函数
ggplot(Pre0)
View(Pre0)


ggplot()+
  geom_line(data=Pre0,
            aes(Hb,yhat,colour=gender),alpha=0.7)+
  scale_color_nejm()+ ##采用ggsci包中英格兰调色,也可以其他
  geom_ribbon(data=Pre0,
              aes(Hb, ymin=lower,ymax=upper,fill=gender),alpha=0.1)+
  scale_fill_nejm()+
  geom_hline(yintercept=1,linetype=2,size=0.75)

解决

as.factor把sex变量转化为因子即可;

Pre0 <-rms::Predict(fit,Hb,fun=exp,type="predictions",ref.zero=TRUE,conf.int = 0.95,digits=2);
##其中fun是转化函数
ggplot(Pre0)
View(Pre0)


ggplot()+
  geom_line(data=Pre0,
            aes(age,yhat,colour=as.factor(sex)),alpha=0.7)+
  scale_color_nejm()+ ##采用ggsci包中英格兰调色,也可以其他
  geom_ribbon(data=Pre0,
              aes(age, ymin=lower,ymax=upper,fill=as.factor(sex)),alpha=0.1)+
  scale_fill_nejm()+
  geom_hline(yintercept=1,linetype=2,size=0.75)

完整错误:

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

Traceback:
1. FUN(X[[i]], ...)
2. tryCatch(withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler), error = outer_handler)
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. doTryCatch(return(expr), name, parentenv, handler)
6. withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler)
7. repr::mime2repr[[mime]](obj)
8. repr_text.default(obj)
9. paste(capture.output(print(obj)), collapse = "\\n")
10. capture.output(print(obj))
11. withVisible(...elt(i))
12. print(obj)
13. print.ggplot(obj)
14. ggplot_build(x)
15. ggplot_build.ggplot(x)
16. lapply(data, scales_train_df, scales = npscales)
17. FUN(X[[i]], ...)
18. lapply(scales$scales, function(scale) scale$train_df(df = df))
19. FUN(X[[i]], ...)
20. scale$train_df(df = df)
21. f(..., self = self)
22. self$train(df[[aesthetic]])
23. f(..., self = self)
24. self$range$train(x, drop = self$drop, na.rm = !self$na.translate)
25. f(..., self = self)
26. scales::train_discrete(x, self$range, drop = drop, na.rm = na.rm)
27. stop("Continuous value supplied to discrete scale", call. = FALSE)

#参考示例mtcars

ggplot(mtcars, aes(x=wt, y=mpg, color=as.factor(cyl), shape=as.factor(cyl))) +
  geom_point() + 
  geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+
  scale_shape_manual(values=c(3, 16, 17))+ 
  scale_color_manual(values=c('#999999','#E69F00', '#56B4E9'))+
  theme(legend.position="top")

参考:"Error: Continuous value supplied to discrete scale" in default data set example mtcars and ggplot2

参考: R

参考:ggplot2

以上是关于ERROR while rich displaying an object: Error: Continuous value supplied to discrete scale的主要内容,如果未能解决你的问题,请参考以下文章

严重: Error while registering Oracle JDBC Diagnosability MBean.

重新渲染rich:dataTable的特定行

OracleOGG error while loading shared libraries

成功解决Error while trying to retrieve text for error ORA-12154

### The error may involve defaultParameterMap ### The error occurred while setting parameters

riched32.dll riched20.dll msftedit.dll 解析