使用R绘制花瓣图
上篇博客,我们讲到了使用R包绘制不超过五组数据集的维恩图,末尾留了个尾巴:就是数据集超过五组数据集怎么绘制呢,当然可以选择绘制花瓣图进行数据的分析和可视化。下面我就带了大家使用R绘制花瓣图!
废话不多说,直接上R绘图代码:
测试数据文件内容长这样!需要的请在该博文下面留言联系我!library(rio)
library(plotrix)
## 2.读取数据venn_data_index <- list.files(path = "./", pattern = "^venn_data")
venn_data <- import(venn_data_index)
sample_id <- colnames(venn_data)
otu_id <- unique(venn_data[,1])
otu_id <- otu_id[otu_id != '']
core_otu_id <- otu_id
otu_num <- length(otu_id)
## 3.遍历数据文件获取数据
for (i in 2:ncol(venn_data)) {
otu_id <- unique(venn_data[,i])
otu_id <- otu_id[otu_id != '']
core_otu_id <- intersect(core_otu_id, otu_id)
otu_num <- c(otu_num, length(otu_id))
}
core_num <- length(core_otu_id)
## 4.定义备选颜色(示例数据20个样本,所以我设置了20种颜色)ellipse_col <- c('#6181BD4E','#F348004E','#64A10E4E','#9300264E','#464E044E','#049a0b4E','#4E0C664E','#D000004E','#FF6C004E','#FF00FF4E','#c7475b4E','#00F5FF4E','#BDA5004E','#A5CFED4E','#f0301c4E','#2B8BC34E','#FDA1004E','#54adf54E','#CDD7E24E','#9295C14E')
## 5.创建绘图函数:flower_plot()
flower_plot <- function(sample, otu_num, core_otu, start, a, b, r, ellipse_col, circle_col) {
par( bty = 'n', ann = F, xaxt = 'n', yaxt = 'n', mar = c(1,1,1,1))
plot(c(0,10),c(0,10),type='n')
n <- length(sample)
deg <- 360 / n
res <- lapply(1:n, function(t){
draw.ellipse(x = 5 + cos((start + deg * (t - 1)) * pi / 180),
y = 5 + sin((start + deg * (t - 1)) * pi / 180),
col = ellipse_col[t],
border = ellipse_col[t],
a = a, b = b, angle = deg * (t - 1))
text(x = 5 + 2.5 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 2.5 * sin((start + deg * (t - 1)) * pi / 180),
otu_num[t])
if (deg * (t - 1) < 180 && deg * (t - 1) > 0 ) {
text(x = 5 + 3.3 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 3.3 * sin((start + deg * (t - 1)) * pi / 180),
sample[t],
srt = deg * (t - 1) - start,
adj = 1,
cex = 1
)
} else {
text(x = 5 + 3.3 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 3.3 * sin((start + deg * (t - 1)) * pi / 180),
sample[t],
srt = deg * (t - 1) + start,
adj = 0,
cex = 1
)
}
})
draw.circle(x = 5, y = 5, r = r, col = circle_col, border = NA)
text(x = 5, y = 5, paste('Core:', core_otu))
}
## 6.调用上述函数作图(保存图片到本地文件夹中)png('flower.png', width = 1500, height = 1500, res = 200, units = 'px')
flower_plot(sample = sample_id, otu_num = otu_num, core_otu = core_num,
start = 90, a = 0.5, b = 2, r = 1, ellipse_col = ellipse_col, circle_col = 'white')
dev.off()
pdf('flower.pdf', width = 15, height = 15)
flower_plot(sample = sample_id, otu_num = otu_num, core_otu = core_num,
start = 90, a = 0.5, b = 2, r = 1, ellipse_col = ellipse_col, circle_col = 'white')
dev.off()
## 7.成果展示本次我们的维恩图系列就算完成了,希望对大家有帮助,大家可以通过“跑”(运行)别人的代码来进行快速的R语言的学习!最后,请点赞加关注,有问题欢迎讨论!
相关知识
使用ggplot2绘制风向风速玫瑰图
python绘制4瓣花瓣的花朵
如何使用python画玫瑰花
Python用turtle库绘制图形——漂亮的玫瑰
使用pandas绘制两列csv的直方图
如何使用CorelDRAW绘制简约花瓶
ai怎么绘制玫瑰花:详解AI绘制技巧与步骤
用 R 中 echarts4r 包画花的笔记
使用CAD绘制花朵的技巧与方法
UI设计教程,花瓣图标的绘制方法,AICS6教程
网址: 使用R绘制花瓣图 https://www.huajiangbk.com/newsview665896.html
上一篇: 简单三步,教你画一朵漂亮的写意花 |
下一篇: 微生信 |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039