-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
734 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Package: flowerplot | ||
Title: Flower Plot | ||
Version: 0.1.0 | ||
Author: Wei Dong | ||
Maintainer: Wei Dong <[email protected]> | ||
Description: This Package Is Used To Draw Flower Plot With Multiple Data Sets. | ||
License: GPL (>= 3) | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.1.1 | ||
Depends: R (>= 2.10), plotrix, RColorBrewer | ||
Suggests: rmarkdown, knitr | ||
VignetteBuilder: knitr | ||
NeedsCompilation: no | ||
Packaged: 2021-05-06 13:14:58 UTC; Dell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(flowerplot) | ||
import(RColorBrewer) | ||
import(plotrix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#' @title flower_dat | ||
#' | ||
#' @description used as demo data for this package | ||
#' | ||
#' @docType data | ||
#' @name flower_dat | ||
#' | ||
#' @format A data frame with multiple columns. | ||
#' | ||
#' @examples | ||
#' data(flower_dat) | ||
#' head(flower_dat) | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#' @title flowerplot | ||
#' | ||
#' @description A package for drawing flower plot with multiple data sets. | ||
#' | ||
#' @author Wei Dong <[email protected]> | ||
#' | ||
#' @param data a dataframe with multiple columns. | ||
#' @param angle set the angle angle of rotation in degress. | ||
#' @param a set the radii of the ellipses along the x-axes. | ||
#' @param b set the radii of the ellipses along the y-axes. | ||
#' @param r set the radius of the circle. | ||
#' @param ellipse_col_pal set the color palette for filling the ellipse. | ||
#' @param circle_col set the color for filling the circle. | ||
#' @param label_text_cex set the label text cex. | ||
#' | ||
#' @return A flower plot. | ||
#' @export | ||
#' @import plotrix | ||
#' @import RColorBrewer | ||
#' | ||
#' @examples | ||
#' data(flower_dat) | ||
#' head(flower_dat) | ||
#' | ||
#' flowerplot(flower_dat) | ||
#' flowerplot(flower_dat, a = 0.5, b = 2, r = 1, | ||
#' circle_col = "red", ellipse_col_pal = "Spectral", | ||
#' label_text_cex = 1.5) | ||
#' flowerplot(flower_dat, angle = 60, ellipse_col_pal = "Set3") | ||
flowerplot <- function(data, angle = 90, | ||
a = 1, b = 2, r = 1, | ||
ellipse_col_pal = "Set1", | ||
circle_col = "white", | ||
label_text_cex = 1) | ||
{ | ||
set_name <- colnames(flower_dat) | ||
item_id <- unique(flower_dat[,1]) | ||
item_id <- item_id[item_id != ''] | ||
core_item_id <- item_id | ||
item_num <- length(item_id) | ||
|
||
for (i in 2:ncol(flower_dat)) { | ||
item_id <- unique(flower_dat[,i]) | ||
item_id <- item_id[item_id != ''] | ||
core_item_id <- intersect(core_item_id, item_id) | ||
item_num <- c(item_num, length(item_id)) | ||
} | ||
core_num <- length(core_item_id) | ||
|
||
graphics::par( bty = 'n', ann = F, xaxt = 'n', yaxt = 'n', mar = c(1,1,1,1)) | ||
graphics::plot(c(0,10), c(0,10), type='n') | ||
n <- length(set_name) | ||
# set the angle of degress | ||
deg <- 360 / n | ||
# set the ellipse filling color | ||
colors <- RColorBrewer::brewer.pal(8, ellipse_col_pal) | ||
ellipse_col <- grDevices::colorRampPalette(colors)(n) | ||
|
||
res <- lapply(1:n, function(t){ | ||
plotrix::draw.ellipse(x = 5 + cos((angle + deg * (t - 1)) * pi / 180), | ||
y = 5 + sin((angle + deg * (t - 1)) * pi / 180), | ||
col = ellipse_col[t], | ||
border = ellipse_col[t], | ||
a = a, b = b, | ||
angle = deg * (t - 1)) | ||
graphics::text(x = 5 + 2.5 * cos((angle + deg * (t - 1)) * pi / 180), | ||
y = 5 + 2.5 * sin((angle + deg * (t - 1)) * pi / 180), | ||
item_num[t]) | ||
|
||
if (deg * (t - 1) < 180 && deg * (t - 1) > 0 ) { | ||
graphics::text(x = 5 + 3.3 * cos((angle + deg * (t - 1)) * pi / 180), | ||
y = 5 + 3.3 * sin((angle + deg * (t - 1)) * pi / 180), | ||
set_name[t], | ||
srt = deg * (t - 1) - angle, | ||
adj = 1, | ||
cex = label_text_cex | ||
) | ||
} else { | ||
graphics::text(x = 5 + 3.3 * cos((angle + deg * (t - 1)) * pi / 180), | ||
y = 5 + 3.3 * sin((angle + deg * (t - 1)) * pi / 180), | ||
set_name[t], | ||
srt = deg * (t - 1) + angle, | ||
adj = 0, | ||
cex = label_text_cex | ||
) | ||
} | ||
}) | ||
plotrix::draw.circle(x = 5, y = 5, r = r, col = circle_col, border = NA) | ||
graphics::text(x = 5, y = 5, paste('Core items:', core_num), cex = label_text_cex) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
# generankplot | ||
|
||
<!-- badges: start --> | ||
|
||
<!-- badges: end --> | ||
|
||
The goal of flowerplot is to draw flower plot. | ||
|
||
## Installation | ||
|
||
You can install the released version of flowerplot from | ||
[GitHub](https://github.com/dongwei1220/flowerplot) with: | ||
|
||
``` r | ||
devtools::install_github("dongwei1220/flowerplot") | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
``` r | ||
library(flowerplot) | ||
#> Loading required package: plotrix | ||
#> Warning: package 'plotrix' was built under R version 3.6.3 | ||
#> Loading required package: RColorBrewer | ||
|
||
## basic example code | ||
data(flower_dat) | ||
head(flower_dat) | ||
#> Set1 Set2 Set3 Set4 Set5 Set6 Set7 Set8 | ||
#> 1 ZMIZ1 ADCY5 TNS1 TNS1 TNS1 ZMIZ1 SORBS1 RGS3 | ||
#> 2 TNS1 ACTN4 ZMIZ1 ZMIZ1 ZMIZ1 TNS1 TNS1 FHOD3 | ||
#> 3 CASZ1 SORBS1 RXRA RXRA TSPAN9 CASZ1 ZMIZ1 PPARGC1B | ||
#> 4 NFIC TNS1 AHDC1 NCOR2 MIDN NFIC RBM20 NNMT | ||
#> 5 CACNA1C ZMIZ1 ACTN4 MIDN NCOR2 CACNA1C TSPAN9 SORBS2 | ||
#> 6 AHDC1 RBM20 MIDN AHDC1 AHDC1 AHDC1 SYNPO FAM53B | ||
|
||
flowerplot(flower_dat) | ||
``` | ||
|
||
<img src="man/figures/README-example-1.png" width="100%" /> | ||
|
||
``` r | ||
flowerplot(flower_dat, a = 0.5, b = 2, r = 1, | ||
circle_col = "red", ellipse_col_pal = "Spectral", | ||
label_text_cex = 1) | ||
``` | ||
|
||
<img src="man/figures/README-example-2.png" width="100%" /> | ||
|
||
``` r | ||
flowerplot(flower_dat, angle = 60, ellipse_col_pal = "Set3") | ||
``` | ||
|
||
<img src="man/figures/README-example-3.png" width="100%" /> | ||
|
||
In that case, don’t forget to commit and push the resulting figure | ||
files, so they display on GitHub and CRAN. |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## ---- include = FALSE--------------------------------------------------------- | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
|
||
## ----example, fig.width=7,fig.height=6.5-------------------------------------- | ||
library(flowerplot) | ||
|
||
## basic example code | ||
data(flower_dat) | ||
head(flower_dat) | ||
|
||
flowerplot(flower_dat) | ||
flowerplot(flower_dat, a = 0.5, b = 2, r = 1, | ||
circle_col = "red", ellipse_col_pal = "Spectral", | ||
label_text_cex = 1) | ||
flowerplot(flower_dat, angle = 60, ellipse_col_pal = "Set3") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: "flowerplot-tutorial" | ||
output: rmarkdown::html_vignette | ||
vignette: > | ||
%\VignetteIndexEntry{flowerplot-tutorial} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
``` | ||
|
||
The goal of flowerplot is to draw flower plot. | ||
|
||
## Installation | ||
|
||
You can install the released version of flowerplot from [GitHub](https://github.com/dongwei1220/flowerplot) with: | ||
|
||
``` r | ||
devtools::install_github("dongwei1220/flowerplot") | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
```{r example, fig.width=7,fig.height=6.5} | ||
library(flowerplot) | ||
## basic example code | ||
data(flower_dat) | ||
head(flower_dat) | ||
flowerplot(flower_dat) | ||
flowerplot(flower_dat, a = 0.5, b = 2, r = 1, | ||
circle_col = "red", ellipse_col_pal = "Spectral", | ||
label_text_cex = 1) | ||
flowerplot(flower_dat, angle = 60, ellipse_col_pal = "Set3") | ||
``` | ||
|
Oops, something went wrong.