美文网首页
[R] 之前报错记录收集

[R] 之前报错记录收集

作者: happyxhz | 来源:发表于2019-02-26 17:28 被阅读0次

    Rcolorbrewer简略学习

    参考:R数据可视化手册第12章 R语言实战第三章(p.51)

    library(Rcolorbrewer)
    #展示所有调色板
    display.brewer.all()
    brewer.pal.all
    #利用某调色板
    mycolor <- brewer.pal(n,"BrBG")
    

    在ggplot中调整颜色

    1. 利用Rcolorbrewer
    +scale_fill_hue(palette="Oranges",l=45) #l means luminanace/lightness(亮度)
    #等同于
    +scale_fill_discrete()
    +scale_fill_brewer()
    
    1. 灰度颜色
    +scale_fill_grey()
    
    1. 手动设置颜色
    +scale_fill_manual(values = c('white','red'))
    

    ggplot简介

    地图及其标记 2018-09-26

    1. 使用到的包
    • maps
    • maptools
    • mapdata
    1. 参考资料
    1. 遇到的问题
    # ggplot2作图,墨卡托投影(需要载入包mapproj)
    mapfig <- ggplot(china_map,aes(x=long,y=lat,group=group))+
      geom_path()+coord_map('mercator')
    

    在图中加入dataframe的数据,出现报错

    mapfig + geom_point(df,aes(x=longitude,y=latitude))
    
    #Error: ggplot2 doesn't know how to deal with data of class uneval
    

    解决方法:df之前加入data=
    STACKOVERFLOW

    mapfig + geom_point(data=df,aes(x=longitude,y=latitude))
    
    #Error in FUN(X[[i]], ...) : object 'group' not found
    
    

    解决方法:inherit.aes=FALSE
    stackoverflow

    data.table::fread

    快速读取表格,参考
    R语言data.table包
    https://www.rdocumentation.org/packages/data.table/versions/1.12.8/topics/fread

    R语言异常捕获:

    想做个try、except之类的操作,看了一下有try、还有tryCatch,尝试了一下前者更适合我吧:

    sign <- try(estimateSignatures(mat = laml.tnm, nTry = 6, plotBestFitRes = TRUE))
    # 判断
    if("try-error" %in% class(laml.sign)){
            print('***WARNING:using pConstant =0.1****');
            laml.sign = estimateSignatures(mat = laml.tnm, nTry = 6, pConstant =0.1, plotBestFitRes = TRUE)
    }
    

    参考:
    R语言异常或错误处理
    R异常捕获

    R语言多线程parallel

    library(parallel)
    detectCores()
    # 初始化8个核
    cl <- makeCluster(8)
    x <- 1:38
    parLapply(cl, x, func)
    stopCluster(cl)
    

    参考:
    R语言如何多线程
    R语言多线程

    相关文章

      网友评论

          本文标题:[R] 之前报错记录收集

          本文链接:https://www.haomeiwen.com/subject/ybhzyqtx.html