欢迎关注天善智能微信公众号,我们是专注于商业智能BI,大数据,数据分析领域的垂直社区。 对商业智能BI、大数据分析挖掘、机器学习,python,R等数据领域感兴趣的同学加微信:tstoutiao,邀请你进入头条数据爱好者交流群,数据爱好者们都在这儿。
R语言中包含657种颜色,辅助我们画一幅漂亮的图片,本文介绍了R语言中颜色参考卡的获取以及常用的颜色配比方案。
获取颜色参考卡
#数字型
par(mar=c(0,0,0,0))
plot(0, 0, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")line=31col=21rect( rep((0:(col - 1)/col),line) , sort(rep((0:(line - 1)/line),col),decreasing=T) , rep((1:col/col),line) , sort(rep((1:line/line),col),decreasing=T), border = "light gray" , col=colors()[seq(1,651)])text( rep((0:(col - 1)/col),line)+0.02 , sort(rep((0:(line - 1)/line),col),decreasing=T)+0.01 , seq(1,651) , cex=0.5)
#标识型
par(mar=c(0,0,0,0))
plot(0, 0, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")line=25col=5rect( rep((0:(col - 1)/col),line) , sort(rep((0:(line - 1)/line),col),decreasing=T) , rep((1:col/col),line) , sort(rep((1:line/line),col),decreasing=T), border = "light gray" , col=colors()[seq(1,line*col)])text( rep((0:(col - 1)/col),line)+0.1 , sort(rep((0:(line - 1)/line),col),decreasing=T)+0.015 , colors()[seq(1,line*col)] , cex=1)
#PDFpdf('D:/colours.pdf', height = 120)par(mar = c(0, 10, 3, 0)+0.1, yxs ='i')
barplot(rep(
1,
length(colours())),
col = rev(colours()),
names.arg = rev(colours()), horiz =
TRUE, las =
1, xaxt =
'n',
main = expression(
'Bars of colours in' ~ italic(colours())))dev.
off()
RGB取色
co = rgb((
0:
15)/
15, green =
0, blue =
0, names = paste(
"red",
0:
15, sep =
".")) barplot(
1:
12,col=co)
主题调色板
#rainbow()
barplot(rep(1,41),
col=c(rainbow(n=6, 0, 1/6), 'white', rainbow(n=6, 1/6, 2/6), 'white', rainbow(n=6, 2/6, 3/6), 'white', rainbow(n=6, 3/6, 4/6), 'white', rainbow(n=6, 4/6, 5/6), 'white', rainbow(n=6, 5/6, 6/6)))x.text <- c('赤色','黄色','绿色','青色','蓝色','紫色')axis(side = 1, at=seq(from = 3, length.out = 6, by = 8.5), labels = x.text, cex = 0.75)
#heat.colors() barplot(
1:
6, col = heat.colors(
6))
barplot(
1:
6, col = terrain.colors(
6))
barplot(
1:
6, col = topo.colors(
6))
barplot(
1:
6, col = cm.colors(
6))
RColorBrewer颜色包
查看所有配色色
library(RColorBrewer) display.brewer.all(
type =
'all')
#type=seq离散型, div极端型, qual离散型
取色 brewer.pal(
9,
'BrBG') barplot(
1:
6, col = brewer.pal(
9,
'BrBG')[
1:
6]) brewer.pal()
彩虹
# Red stripes par(bg=
"black") par(mar=c(
0,
0,
0,
0)) plot(
1 ,
1 , xlim=c(
0,
100) , ylim=c(
0,
40) , col=
"black")
for(
i in seq(-250,50,2)){ abline(a = i, b =
0.3, col = rgb(sample(seq(
0,
1,
0.001) ,
1) ,sample(seq(
0,
1,
0.001) ,
1),sample(seq(
0,
1,
0.001) ,
1),
0.7) , lwd=sample(seq(
1:
50),
1) ) }
两幅漂亮的图
data<-numeric()
data<-readLines("https://www.apup.org/images/digits100000.txt") # orig. data source https://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html# subset of 10'000 digitsdataA<-numeric()dataA<-substr(data,1,10000)# colorspal <- colorRampPalette(c("#f2f2f2", "blue"))colors <- pal(10000)# image settings. here manually set limits (by visual eye).dev.new(height=7,width=7)par(bg="black", mar=c(0,0,0,0))plot(x=0,y=0,xlim=c(-50,70), ylim=c(-100,40))# initial valuesa_x <- a_y <- numeric()a_x <- 0; a_y <- 0;# loop decimals. each digit (0-9) represents an individual angle.for(i in 1:nchar(dataA)){ a<-b_x<-b_y<-numeric() a<-as.numeric(substr(dataA,i,i)) b_x<-a_x+sin((2*pi/10)*(a)) # orig. y pos. + change b_y<-a_y+cos((2*pi/10)*(a)) # orig. x pos. + change # draw points. change colors. points(x=c(a_x,b_x),y=c(a_y,b_y),type="l", col=colors[i]) points(x=c(b_x),y=c(b_y),pch=19, col=colors[i],cex=0.3) # initialize next round a_x<-b_x a_y<-b_y
}
text(x=40, y=0, labels=expression(R), col="#f2f2f2", cex=12, pos=4) # titletext(x=52, y=10.6, labels="10000", col="black",cex=0.7, pos=4) # decimal amount
library(grid) dev.new() pushViewport(viewport(width=
1, height=
1, angle=
0, name=
"vp1")) grid.rect()
for(i in
1:
54){ pushViewport(viewport(width=
0.95, height=
0.95, angle=
5, name=
"vp1")) grid.rect() }
转载请保留以下内容:
本文来源自天善社区EasyCharts老师的博客(公众号)。
原文链接: https://ask.hellobi.com/blog/EasyCharts/7770
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » blue颜色代码(blue的代码)
1 评论