zl程序教程

您现在的位置是:首页 >  其他

当前栏目

R语言ggplot2作图时好玩的配色包~使用泰勒斯威夫特专辑的封面颜色

2023-04-18 16:25:42 时间

包的名字是

tayloRswift

对应的github链接是

https://github.com/asteves/tayloRswift

安装方式

install.packages(c("tayloRswift"))

总共涉及到11个专辑的封面

离散型变量或者连续型变量都可以使用

下面用鸢尾花的数据集演示

library(ggplot2)
library(tayloRswift)
colnames(iris)

p1<-ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+
  geom_point(aes(color=Species),size=5)+
  theme_bw()+
  scale_color_taylor(palette = "lover")

p2<-ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+
  geom_point(aes(color=Petal.Length),size=5)+
  theme_bw()+
  scale_color_taylor(palette = "Red",
                     discrete = F,
                     guide="none")

library(patchwork)
p1+p2

配色函数是scale_color_taylor()或者scale_fill_taylor()

默认是离散型配色,如果是连续型数据可以指定参数discrete=F

这个配色风格用到科研上也未尝不可,哈哈哈,大家感兴趣的可以自己试试这个代码