R语言中的基础作图和ggplot2配色系统

颜色代码大全

https://www.cnblogs.com/cnblogs-jcy/p/5689033.html

R语言中的调色板

 palette(value) # obtain the curren palette or set the palette
 palette.pals() # give the names of predefined palettes
 palette.colors() # return a vector of R colors

在这里插入图片描述

RColorBrewer提供的调色盘

其他颜色集可以从R包RColorBrewer中获取,利用命令display.brewer.all()可以显示出该包中全部的颜色集:

library(RColorBrewer)
display.brewer.all()

在这里插入图片描述
palete()#设置全局调色盘
brewer.pal(n, name)#调用相应调色盘的颜色

R语言中配色介绍

R语言作图中颜色的调整往往是通过给参数col赋值来实现的,其接受的类型有:数字、颜色名、rgb()、十六进制。

R语言中通过很多调色板,帮助提供配色方案。

在这里插入图片描述
在这里插入图片描述

R语言中自带的调色板

R语言中自带的调色板有hcl, rainbow, heat, terrain, topo, cm等, 用法如下:

hcl.colors(n, palette = "viridis", alpha = NULL, rev = FALSE, fixup = TRUE)
hcl.pals(type = NULL)
rainbow(n, s = 1, v = 1, start = 0, end = max(1, n - 1)/n, alpha, rev = FALSE)
heat.colors(n, alpha, rev = FALSE)
terrain.colors(n, alpha, rev = FALSE)
topo.colors(n, alpha, rev = FALSE)
cm.colors(n, alpha, rev = FALSE)

在这里插入图片描述

RColorBrewer包提供更多的调色板

RColorBrewer包提供了按照 序列型(sequential)、离散型(diverging)、分类型(qualitative) 提供的三种类型的调色盘。利用display.brewer.all()可以展示出全部的调色板样式:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
随后我们通过brewer.pal(n, name)函数就可以调用相应name的调色板了,例如:
在这里插入图片描述

ggplot2中配色系统的介绍

ggplot2包中对配色系统主要通过以下几个函数实现:

  • 数值型
    • scale_colour/fill_coninuous()
    • scale_fill_distiller()
    • scale_colour/fill_gradient()
    • scale_colour/fill_gradient2()
    • scale_colour/fill_gradientn()
  • 类别型
    • scale_colour/fill_discrete()
    • scale_colour/fill_brewer()
    • scale_colour/fill_manual()
      其中,colour表示轮廓色度量,fill表示填充色度量

数值型配色

类别型配色

scale_colour/fill_brewer()

用法

scale_colour_brewer(
  ...,
  type = "seq",
  palette = 1,
  direction = 1,
  aesthetics = "colour"
)

scale_fill_brewer(
  ...,
  type = "seq",
  palette = 1,
  direction = 1,
  aesthetics = "fill"
)

参数介绍:

… Other arguments passed on to discrete_scale(),
continuous_scale(), or binned_scale(), for brewer, distiller, and
fermenter variants respectively, to control name, limits, breaks,
labels and so forth.

type One of seq (sequential), div (diverging) or qual (qualitative)

palette If a string, will use that named palette. If a number, will
index into the list of palettes of appropriate type. The list of
available palettes can found in the Palettes section.

direction Sets the order of colours in the scale. If 1, the default,
colours are as output by RColorBrewer::brewer.pal(). If -1, the order
of colours is reversed.

aesthetics Character string or vector of character strings listing
the name(s) of the aesthetic(s) that this scale works with. This can
be useful, for example, to apply colour settings to the colour and
fill aesthetics at the same time, via aesthetics = c(“colour”,
“fill”).

values if colours should not be evenly positioned along the gradient
this vector gives the position (between 0 and 1) for each colour in
the colours vector. See rescale() for a convenience function to map an
arbitrary range to between 0 and 1.

space colour space in which to calculate gradient. Must be “Lab” -
other values are deprecated.

na.value Colour to use for missing values

guide Type of legend. Use “colourbar” for continuous colour bar, or
“legend” for discrete colour legend.

scale_colour/fill_brewer()是利用已有的颜色集进行配色的,ggplot2中自带的颜色集有:
在这里插入图片描述

其他颜色集可以从R包RColorBrewer中获取,利用命令display.brewer.all()可以显示出该包中全部的颜色集:

library(RColorBrewer)
display.brewer.all()

在这里插入图片描述

scale_colour/fill_manual()

https://zhuanlan.zhihu.com/p/80849532

ggsci为ggplot2提供期刊配色

ggsci是一款优秀的ggplot2的配色包,包含了常见杂志的配色,比如lancet,jco,jama,nejm等,主要通过以下2句代码进行配色:

scale_folor_palname
scale_fill_palname

在这里插入图片描述
可参考:https://zhuanlan.zhihu.com/p/454703155

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值