在 ggplot2 r 中操纵 geom_bar 和 coord_polar 的描绘
manipulate delineation of geom_bar and coord_polar in ggplot2 r
我正在 ggplot 中使用 polar_coord 构建同心圆图表,我需要去掉特定的线。这是代码和情节:
df <- data.frame(A=letters[1:12],
B=c(rep("Dim_1",4),rep("Dim_2",4),rep("Dim_3",4)),
C=c(rep("Ind_1",2),rep("Ind_2",2),rep("Ind_3",2),rep("Ind_2",2),rep("Ind_5",2),rep("Ind_6",2)))
ggplot(df,aes(factor(1),fill=C))+
geom_bar(width = 1,colour="black")+
coord_polar()+
scale_fill_manual(values = c("#FFFFFF","#CCCCCC","#CCCCCC","#999999","#999999"))
如何去除从圆心到圆顶的直线?由于这个极坐标图是由条形图 (geom_bar
) 制成的,另一种提问方式是,如何去掉每个条形底部的边框,而不是侧面或顶部的边框?
看看以下是否适合您?注释代码中的解释:
ggplot(df, aes(factor(1), fill = C)) +
geom_bar(width = 1, colour = NA) + # hide all outlines in geom_bar
stat_count(aes(yintercept = cumsum(rev(..count..))), # add only the top line for each
geom = "hline") + # bar in the stack
coord_polar() +
# optional: add black outline to the fill legend
scale_fill_manual(values = c("#FFFFFF","#CCCCCC","#CCCCCC","#999999","#999999"),
guide = guide_legend(override.aes = list(color = "black")))
我正在 ggplot 中使用 polar_coord 构建同心圆图表,我需要去掉特定的线。这是代码和情节:
df <- data.frame(A=letters[1:12],
B=c(rep("Dim_1",4),rep("Dim_2",4),rep("Dim_3",4)),
C=c(rep("Ind_1",2),rep("Ind_2",2),rep("Ind_3",2),rep("Ind_2",2),rep("Ind_5",2),rep("Ind_6",2)))
ggplot(df,aes(factor(1),fill=C))+
geom_bar(width = 1,colour="black")+
coord_polar()+
scale_fill_manual(values = c("#FFFFFF","#CCCCCC","#CCCCCC","#999999","#999999"))
如何去除从圆心到圆顶的直线?由于这个极坐标图是由条形图 (geom_bar
) 制成的,另一种提问方式是,如何去掉每个条形底部的边框,而不是侧面或顶部的边框?
看看以下是否适合您?注释代码中的解释:
ggplot(df, aes(factor(1), fill = C)) +
geom_bar(width = 1, colour = NA) + # hide all outlines in geom_bar
stat_count(aes(yintercept = cumsum(rev(..count..))), # add only the top line for each
geom = "hline") + # bar in the stack
coord_polar() +
# optional: add black outline to the fill legend
scale_fill_manual(values = c("#FFFFFF","#CCCCCC","#CCCCCC","#999999","#999999"),
guide = guide_legend(override.aes = list(color = "black")))