R语言|绘制waffle chart 二维码
6
作者:图图来源:图图云平台 R语言绘制waffle chart library(waffle) library(ggplot2) library(dplyr) # 创建数据集 df <- data.frame(group = LETTERS[1:5], value = c(25, 16, 21, 15,23 )) # 绘图 ggplot(df, aes(fill = group, values = value)) + geom_waffle(n_rows = 10, size = 0.33, colour = "white") + scale_fill_manual(name = NULL, values = c("#BA182A", "#FF8288", "#FFDBDD","#FEB24C", "#FC4E2A"), labels = c("A", "B", "C","D","E")) + coord_equal() + theme_void() library(ggplot2) library(RColorBrewer) library(reshape2) #数据 nrows <- 8 categ_table <- round(table(mpg$class ) * ((nrows*nrows)/(length(mpg$class)))) sort_table<-sort(categ_table,index.return=TRUE,decreasing = FALSE) Order<-sort(as.data.frame(categ_table)$Freq,index.return=TRUE,decreasing = FALSE) df <- expand.grid(y = 1:nrows, x = 1:nrows) df$category<-factor(rep(names(sort_table),sort_table), levels=names(sort_table)) #颜色 Colormap<-brewer.pal(length(sort_table), "Set2") #绘图 ggplot(df, aes(x = y, y = x, fill = category)) + geom_tile(color = "white", size = 0.25) + geom_point(color = "black",shape=21,size=6) + coord_fixed(ratio = 1)+ scale_x_continuous(trans = 'reverse') + scale_y_continuous(trans = 'reverse') + scale_fill_manual(name = "Category", values = Colormap)+ theme(panel.background = element_blank(), plot.title = element_text(size = rel(1.2)), legend.position = "right") “作图帮”微信公众号同步更新 可添加下方微信进入【生信作图交流群】,群内免费分享绘图代码与示例数据 上一篇R语言|绘制堆叠面积图
|