我想使用coord_polar通过一个简单的条形图来可视化我的数据框。我正在尝试复制此屏幕截图:
这是我的尝试:
p <- ggplot(data=df, aes(x=Month, y=Percent)) +
geom_col(aes(fill= Month ), width = 0.87 )+
coord_polar()+
labs(title="some title ",
subtitle="% of total number of something",
x="",
y="",
caption="Reaserch")+
theme_minimal(10) +
theme(legend.position = "none",
text=element_text(family="Courier"),
plot.title=element_text(size=12, hjust=0.2, face='bold'),
plot.subtitle=element_text(size=11, hjust=0.2),
axis.text.x = element_text(size=12, hjust=0.1, face='bold'),
axis.title.x = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks.y = element_blank())
我想删除背景网格和左上轴,并显示饼图中每个记录的月份和值(例如8月68%)+在哪里定义color = "Yellow"
的正确位置?
# reproducible sample data
df <- tibble::tribble(
~Month, ~Percent,
"Jan", 68,
"Feb", 68,
"Mar", 68,
"Apr", 68,
"May", 68,
"June", 65,
"July", 52,
"Aug", 60,
"Sept", 68,
"Oct", 68,
"Nov", 68,
"Dec", 68
)
答案 0 :(得分:3)
df$Month_label = paste0(df$Month, "\n", df$Percent, "%") %>% fct_inorder
ggplot(data=df, aes(x=Month_label, y=Percent)) +
geom_col(fill = "#ffc97b", width = 0.87 )+
geom_text(aes(label = Month_label, y = Percent - 10)) +
coord_polar()+
labs(title="some title ",
subtitle="% of total number of something",
x="",
y="",
caption="Research")+
theme_minimal(10) +
theme(legend.position = "none",
axis.text = element_blank(),
text=element_text(family="Courier"),
plot.title=element_text(size=12, hjust=0.2, face='bold'),
plot.subtitle=element_text(size=11, hjust=0.2),
panel.grid = element_blank(),
axis.ticks.y = element_blank())