gsc*_*ott 1 plot visualization r ggplot2 ggvis
给定一个包含因子列 (X1) 和小计列 (X2) 的数据集
X1 X2
1 1 12
2 2 200
3 3 23
4 4 86
5 5 141
Run Code Online (Sandbox Code Playgroud)
我想创建一个这样的图形:
这给出了 x2 占 X2 总数的百分比,除以 X1。
编辑:清晰度和添加数据集的可重复性
例如
set.seed(1234)
df <- data.frame(x = 1:6)
df$y <- runif(nrow(df))
df$type <- sample(letters, nrow(df))
ggplot(df, aes(x+-.5, y, fill=type)) +
geom_bar(stat="identity", width=1) +
coord_polar(start = pi/2) +
scale_x_continuous(limits = c(0, nrow(df)*2)) +
geom_text(aes(label=scales::percent(y))) +
ggthemes::theme_map() + theme(legend.position = c(0,.15))
Run Code Online (Sandbox Code Playgroud)
给你