ggplot画鸡冠花图

鸡冠花图,又称为玫瑰图,可以通过极坐标coord_polar()改变barplot(类似于圆环图、扇形图、饼图)来获得。

首先画一个简单的bar图

library(ggplot2)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = cut),
show.legend = FALSE,
width = 1
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)

bar

通过coord_polar() 函数使用极坐标系将barplot改为鸡冠花图。

bar + coord_polar()

还可以通过调整width来调整距离,如将width改成0.5

library(ggplot2)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = cut),
show.legend = FALSE,
width = 0.5
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)
bar + coord_polar()

选自《R数据科学》

欢迎各位关注!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。