来源:https://www.r-graph-gallery.com/297-circular-barplot-with-groups/

# Create dataset
data=data.frame(individual=paste( "Mister ", seq(1,60), sep=""),value=sample( seq(10,100), 60, replace=T)
)# Set a number of 'empty bar'
empty_bar=10# Add lines to the initial dataset
to_add = matrix(NA, empty_bar, ncol(data))
colnames(to_add) = colnames(data)
data=rbind(data, to_add)
data$id=seq(1, nrow(data))# Get the name and the y position of each label
label_data=data
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /number_of_bar     # I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)# Make the plot
p = ggplot(data, aes(x=as.factor(id), y=value)) +       # Note that id is a factor. If x is numeric, there is some space between the first bargeom_bar(stat="identity", fill=alpha("green", 0.3)) +ylim(-100,120) +theme_minimal() +theme(axis.text = element_blank(),axis.title = element_blank(),panel.grid = element_blank(),plot.margin = unit(rep(-1,4), "cm") ) +coord_polar(start = 0) + geom_text(data=label_data, aes(x=id, y=value+10, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) p

#library(tidyverse)# Create dataset
data=data.frame(individual=paste( "Mister ", seq(1,60), sep=""),group=c( rep('A', 10), rep('B', 30), rep('C', 14), rep('D', 6)) ,value=sample( seq(10,100), 60, replace=T)
)# Set a number of 'empty bar' to add at the end of each group
empty_bar=4
to_add = data.frame( matrix(NA, empty_bar*nlevels(data$group), ncol(data)) )
colnames(to_add) = colnames(data)
to_add$group=rep(levels(data$group), each=empty_bar)
data=rbind(data, to_add)
data=data %>% arrange(group)
data$id=seq(1, nrow(data))# Get the name and the y position of each label
label_data=data
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /number_of_bar     # I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)# Make the plot
p = ggplot(data, aes(x=as.factor(id), y=value, fill=group)) +       # Note that id is a factor. If x is numeric, there is some space between the first bargeom_bar(stat="identity", alpha=0.5) +ylim(-100,120) +theme_minimal() +theme(legend.position = "none",axis.text = element_blank(),axis.title = element_blank(),panel.grid = element_blank(),plot.margin = unit(rep(-1,4), "cm") ) +coord_polar() + geom_text(data=label_data, aes(x=id, y=value+10, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) p

# library
#library(tidyverse)# Create dataset
data=data.frame(individual=paste( "Mister ", seq(1,60), sep=""),group=c( rep('A', 10), rep('B', 30), rep('C', 14), rep('D', 6)) ,value=sample( seq(10,100), 60, replace=T)
)data = data %>% arrange(group,value)
# Set a number of 'empty bar' to add at the end of each group
empty_bar=4
to_add = data.frame( matrix(NA, empty_bar*nlevels(data$group), ncol(data)) )
colnames(to_add) = colnames(data)
to_add$group=rep(levels(data$group), each=empty_bar)
data=rbind(data, to_add)
data=data %>% arrange(group)
data$id=seq(1, nrow(data))# Get the name and the y position of each label
label_data=data
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /number_of_bar     # I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)# Make the plot
p = ggplot(data, aes(x=as.factor(id), y=value, fill=group)) +       # Note that id is a factor. If x is numeric, there is some space between the first bargeom_bar(stat="identity", alpha=0.5) +ylim(-100,120) +theme_minimal() +theme(legend.position = "none",axis.text = element_blank(),axis.title = element_blank(),panel.grid = element_blank(),plot.margin = unit(rep(-1,4), "cm") ) +coord_polar() + geom_text(data=label_data, aes(x=id, y=value+10, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) p

可视化之circular barplot相关推荐

  1. 如何检查计算机上安装的DirectX版本?

    这是显示使用DirectX诊断工具检查计算机上安装的Microsoft DirectX版本的指南. 1.单击" 开始 "或" Windows按钮 ",然后单击& ...

  2. 数据可视化系列(六):场景案例显神通

    数据可视化的图表种类繁多,各式各样,因此我们需要掌握如何在特定场景下使用特定的图表. 数据可视化是为业务目的服务的,好的可视化图表可以起到清晰准确反映业务结果的目的,在选择使用何种图表时,通常我们需要 ...

  3. datawhale可视化学习第六章 场景案例显神通

    数据可视化的图表种类繁多,各式各样,因此我们需要掌握如何在特定场景下使用特定的图表. 数据可视化是为业务目的服务的,好的可视化图表可以起到清晰准确反映业务结果的目的,在选择使用何种图表时,通常我们需要 ...

  4. 第六回:场景案例显神通

    数据可视化的图表种类繁多,各式各样,因此我们需要掌握如何在特定场景下使用特定的图表. 数据可视化是为业务目的服务的,好的可视化图表可以起到清晰准确反映业务结果的目的,在选择使用何种图表时,通常我们需要 ...

  5. 第六章:Matplotlib之场景案例显神通

    第六章:场景案例显神通 数据可视化的图表种类繁多,各式各样,因此我们需要掌握如何在特定场景下使用特定的图表. 数据可视化是为业务目的服务的,好的可视化图表可以起到清晰准确反映业务结果的目的,在选择使用 ...

  6. Seaborn初学指南

    学习笔记,仅供参考,有错必纠 文章目录 Seaborn 学习 Seaborn 简介 安装 Seaborn Seaborn 图形可视化 distplot 直方图 barplot 条形图 countplo ...

  7. pandas分析各国家交易情况

    数据集来源: https://archive.ics.uci.edu/ml/datasets/Online%20Retail #coding:utf-8import pandas as pd impo ...

  8. pandas基础知识

    一,创建series  import pandas as pd countries = ['中国', '美国', '澳大利亚'] countries_s = pd.Series(countries) ...

  9. Python|泰坦尼克号幸存者画像

    01 幸存者 泰坦尼克号的沉没,是人为的悲剧,1800人罹难者近70%,让我们一起来看看泰坦尼克号的幸存者都有哪些特征吧. 先给出分析框架 一切的分析都建立在数据清洗之后 幸存率的分析非常重要,下面将 ...

最新文章

  1. anndroid ndk使用
  2. python怎么读excel文件-python如何读写excel文件
  3. 深划痕需要大面积补漆吗_剐蹭了需要立马补漆吗?这些小技巧能省不少!
  4. 将二叉树的叶子结点转换成单链表,并返回最左叶子结点的地址(链头)
  5. boost::hana::extract用法的测试程序
  6. Spring Boot中使用模板引擎引用资源
  7. LeetCode 397. 整数替换(Integer Replacement)
  8. Reporting Services 在WIN7和2008下出现“授予的权限不足,无法执行此操作。 (rsAccessDenied)”的解决办...
  9. 协同过滤推荐算法的用户向量相似度计算
  10. 超级PK:Sybase与Oracle的十二场性能比拼
  11. android x5webview截长图
  12. linux防火墙配置怎么修改密码,Linux系统修改防火墙配置
  13. 【初学大数据】CentOS7安装hadoop3.3.2完全分布式详细流程
  14. python星星闪烁_python实现while循环打印星星的四种形状
  15. Windows性能监控perfmon工具的使用和性能指标的分析
  16. angular primeng 弹出对话框修改
  17. iOS模拟键盘长按删除
  18. CPU温度过高会导致电脑死机么
  19. 顺丰笔试-赏金猎人2020-08-20(参考时间最大利益)
  20. 从Adobe调查问卷看原型设计工具大战

热门文章

  1. BZOJ2069 POI2004ZAW(最短路)
  2. nyoj 1275-导弹发射 //lis
  3. 赵小楼《天道》《遥远的救世主》深度解析(142)贫富差距化是常态,扶贫不是拉平平均值,而是强者去关注弱者
  4. 飞腾cpu服务器浪潮信息,浪潮发布国产飞腾CPU服务器
  5. bzoj1724【Usaco2006 Nov】Fence Repair 切割木板
  6. CRM系统慢慢转为企业微信SCRM
  7. 推荐一个好用的开源的报表平台——JNPF可视化平台
  8. win7/win10下KiWi Syslog服务器的安装与配置
  9. 谈谈第一次Web项目的感想(上)
  10. 临床试验中lm是什么职位_除了CRX职位,临床试验中还有这些岗位