# 制作圆形堆积条形图

#### to make a Circular stacked barplot

``````data <- isolate_from.ORIGEN %>% gather(key = "observation", value="value", -c(1,2))

#isolate_from.ORIGEN

# Set a number of 'empty bar' to add at the end of each group

empty_bar <- 2
nObsType <- nlevels(as.factor(data\$observation))
to_add <- data.frame( matrix(NA, empty_bar*nlevels(data\$YEAR)*nObsType, ncol(data)) )
to_add\$YEAR <- rep(levels(data\$YEAR), each=empty_bar*nObsType )
data <- rbind(data, to_add)
data <- data %>% arrange(YEAR, FROM)
data\$id <- rep( seq(1, nrow(data)/nObsType) , each=nObsType)

# Get the name and the y position of each label

label_data <- data %>% group_by(id, observation) %>% summarize(tot=sum(count))
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)

# prepare a data frame for base lines

base_data <- data %>%
group_by(YEAR) %>%
summarize(start=min(id), end=max(id) - empty_bar) %>%
rowwise() %>%
mutate(title=mean(c(start, end)))

# prepare a data frame for grid (scales)

grid_data <- base_data
grid_data\$end <- grid_data\$end[ c( nrow(grid_data), 1:nrow(grid_data)-1)] + 1
grid_data\$start <- grid_data\$start - 1
grid_data <- grid_data[-1,]
``````

1 R中的圆形堆积条形图

2 如何制作一个带有多个变量的条形图的堆积条形图

2013-11-23 13:53:19 1 123   r
3 在for循环中制作堆积的条形图

4 在 Pandas seaborn 中制作堆积条形图

2020-10-07 19:10:02 1 309   seaborn
5 如何为Pandas DataFrame制作堆积条形图？

2013-07-24 12:54:41 1 926   pandas
6 如何制作混淆矩阵的堆叠条 plot

7 制作一个带有空心圆形的圆形条形图（又名赛道图）

8 堆积的条形图被一个值淹没

9 堆积条形图

10 ％堆积条形图

2016-04-25 13:02:29 0 67   r