饼图一般用来呈现一组数据中各项的大小与总和的比例情况。用R画饼图是很简单的,但是如果我们需要将其调整的美观大方是很难的。最新的一个R包-tastypie可以解决这个问题,自身带了几十种饼图模版可以满足各类饼图的需求。
下面简单来看看tastypie的安装和使用:
# 安装
install.packages("tastypie")
# 或者安装开发版
devtools::install_github("PaoloDalena/tastypie")
示例:
library(tastypie)
#> $$ $$ $$
#> __||__||__||__
#> | * * * * * * *|
#> |* * * * * * * |
#> | * * * * * * *|
#> |______________|
#> _ _ _
#> | |_ ___ ___ | |_ _ _ ___ |_| ___
#> | _|| .'||_ -|| _|| | || . || || -_|
#> |_| |__,||___||_| |_ || _||_||___|
#> |___||_|
example <- data.frame(
c("a. Is", "b. Not", "c. The", "d. Only", "e. One"),
c(2.9, 6.9, 4.20, 13.12, 6.66)
)
pie_bake(data = example, template = "red1", perc = TRUE,
title = "Perhaps", group_name = "She")
pie_bake_pro(data = example, template = "dart5",
title = "Perhaps", group_name = "She")
如果你纠结用哪一个模版,可以试试pie_discover()
随机使用模版
pie_discover()
又或者,你想查看模版的示例,可以使用pie_templates()
:
pie_templates("eaten4", n_groups = 9)
当然,tastypie提供了不止上面提到的这些模版,我们可以通过pie_template_list
和 pie_template_list_pro
来查看所有模版:
pie_template_list # 使用 pie_bake()
#> [1] "basic1" "basic2" "basic3" "basic4" "basic5" "bw1"
#> [7] "bw2" "bw3" "bw4" "bw5" "blue1" "blue2"
#> [13] "blue3" "blue4" "blue5" "red1" "red2" "red3"
#> [19] "red4" "red5" "rainbow1" "rainbow2" "rainbow3" "rainbow4"
#> [25] "rainbow5" "donut1" "donut2" "donut3" "donut4" "donut5"
pie_template_list_pro # 使用 pie_bake_pro()
#> [1] "eaten1" "eaten2" "eaten3" "eaten4" "eaten5"
#> [6] "dart1" "dart2" "dart3" "dart4" "dart5"
#> [11] "eye1" "eye2" "eye3" "eye4" "eye5"
#> [16] "watermelon1" "watermelon2" "watermelon3" "watermelon4" "watermelon5"
参考资料:
1.https://paolodalena.github.io/tastypie/
2.https://github.com/PaoloDalena/tastypie/