#install.packages("ggpie")
rm(list = ls())
###############################input data 
library(ggpie)
## Warning: 程辑包'ggpie'是用R版本4.2.3 来建造的
library(ggplot2)
## Warning: 程辑包'ggplot2'是用R版本4.2.3 来建造的
data(iris)
# check data used
str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
# with no label
ggpie(data = iris[1:120, ], group_key = "Species", count_type = "full",label_type = "none")

ggpie(data = iris[1:120, ], group_key = "Species", count_type = "full",
      label_info = "all", label_type = "circle",
      label_size = 4, label_pos = "out")

#################
ggpie(data = iris[1:120, ], group_key = "Species", count_type = "full",
      label_info = "all", label_type = "circle", label_split = NULL,
      label_size = 4, label_pos = "in")

################
ggpie(data = iris[1:120, ], group_key = "Species", count_type = "full",
      label_info = "all", label_type = "horizon",
      label_size = 4, label_pos = "out" )

###############
ggdonut(data = iris[1:120, ], group_key = "Species", count_type = "full",
        label_info = "all", label_type = "circle",
        label_size = 4, label_pos = "out")

##############
ggdonut(data = iris[1:120, ], group_key = "Species", count_type = "full",
        label_info = "all", label_type = "circle", label_split = NULL,
        label_size = 4, label_pos = "in")

#############
ggdonut(data = iris[1:120, ], group_key = "Species", count_type = "full",
        label_info = "all", label_type = "horizon",
        label_size = 4, label_pos = "in")

############
ggdonut(data = iris[1:120, ], group_key = "Species", count_type = "full",
        label_info = "all", label_type = "horizon",
        label_size = 4, label_pos = "in", label_threshold = 30)

#############
p1= ggpie3D(data = iris[1:120, ], group_key = "Species", count_type = "full", tilt_degrees = -10, label_size=2) + 
  ggtitle("tilt_degrees = -10") + 
  theme(plot.title = element_text(hjust = 0.5))
p1

p2= ggpie3D(data = iris[1:120, ], group_key = "Species", count_type = "full", tilt_degrees = -40, label_size=2) + 
  ggtitle("tilt_degrees = -40") + 
  theme(plot.title = element_text(hjust = 0.5))
p2

p3= ggpie3D(data = iris[1:120, ], group_key = "Species", count_type = "full", tilt_degrees = -10, 
            start_degrees = 60, label_size=2) + 
  ggtitle("start_degrees = 60") + 
  theme(plot.title = element_text(hjust = 0.5))
p3

p4= ggpie3D(data = iris[1:120, ], group_key = "Species", count_type = "full", tilt_degrees = -10, 
            start_degrees = 180, label_size=2) + 
  ggtitle("start_degrees = 180") + 
  theme(plot.title = element_text(hjust = 0.5))
p4

cowplot::plot_grid(p1,p2,p3,p4,ncol = 2)

######################
iris$label <- rep(LETTERS[1:5], 30)
ggnestedpie(data = iris[1:120, ], group_key = c("Species", "label"), count_type = "full",
            inner_label_info = "all", inner_label_split = NULL,
            inner_label_threshold = 5, inner_label_size = 2,
            outer_label_type = "circle", outer_label_pos = "in", outer_label_info = "all")
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.

#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.

###################
# pie plot
p1=ggrosepie(data = iris[1:120, ], group_key = "Species", count_type = "full", label_info = "all",
             show_tick=F,donut_frac=NULL)
p1

# donut plot
p2=ggrosepie(iris[1:120, ], group_key = "Species", count_type = "full", label_info = "all",
             show_tick=F,donut_frac=0.3,donut_label_size=3)
p2

cowplot::plot_grid(p1,p2)

#######################
# pie plot
p1=ggrosepie(iris[1:120, ], group_key = "Species", count_type = "full", label_info = "all",
             donut_frac=NULL)
p1

# donut plot
p2=ggrosepie(iris[1:120, ], group_key = "Species", count_type = "full", label_info = "all",
             donut_frac=0.3,donut_label_size=3)
p2

cowplot::plot_grid(p1,p2)

####reff https://cran.r-project.org/web/packages/ggpie/vignettes/ggpie.html