Rcolorbrewer简略学习
参考:R数据可视化手册第12章 R语言实战第三章(p.51)
library(Rcolorbrewer)
#展示所有调色板
display.brewer.all()
brewer.pal.all
#利用某调色板
mycolor <- brewer.pal(n,"BrBG")
在ggplot中调整颜色
- 利用Rcolorbrewer
+scale_fill_hue(palette="Oranges",l=45) #l means luminanace/lightness(亮度)
#等同于
+scale_fill_discrete()
+scale_fill_brewer()
- 灰度颜色
+scale_fill_grey()
- 手动设置颜色
+scale_fill_manual(values = c('white','red'))
ggplot简介
地图及其标记 2018-09-26
- 使用到的包
- maps
- maptools
- mapdata
- 参考资料
- R数据可视化手册第13章
- R地图系列(1):maptools包绘制中国地图
- 遇到的问题
# 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)