Skip to content

Commit

Permalink
fixed issues in desc file and main function
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSt099 committed Feb 13, 2024
1 parent 0b64ecd commit cf84420
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ Package: circlesplot
Type: Package
Title: Visualize Proportions with Circles in a Plot
Version: 1.0.0
Authors@R: c(person("BenSt099", "Developer", role = c("aut", "cre","cph"),
Authors@R: c(person("BenSt099", role = c("aut", "cre","cph"),
email = "benst099@proton.me"))
Description: Method for visualizing proportions between objects of different sizes.
Description: Method for visualizing proportions between objects of different sizes.
The proportions are drawn as circles with different diameters, which makes them ideal
for visualizing proportions between planets.
License: MIT + file LICENSE
Imports:
plotrix
Expand Down
25 changes: 16 additions & 9 deletions R/circlesplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
#'
#' @examples
#'
#' \dontrun{
#' \donttest{
#' library('plotrix')
#' colors = c('#D1BBD7', '#AE76A3', '#882E72', '#1965B0', '#5289C7', '#7BAFDE', '#4EB265', '#90C987')
#' values = c(5,5,4,5,5,5,2,1)
#' text = c('8','7','6','5','4','3','2','1')
#' circlesplot(cp_vals=values, cp_text=text, cp_max=3L, cp_title="Some title", cp_color=colors)}
#' circlesplot(cp_vals=values, cp_text=text, cp_max=3L, cp_title="Some title", cp_color=colors)
#' }
#'
#' \dontrun{
#' # Proportions among planets
#' library('plotrix')
#' library("viridis")
#' colors = c('#D1BBD7', '#AE76A3', '#882E72', '#1965B0', '#5289C7', '#7BAFDE', '#4EB265', '#90C987')
#' planets = c('Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune')
#' diameter = c(4879.4,12103.6,12756.3,6792.4,142984,120536,51118,49528)
#' circlesplot(cp_vals=diameter, cp_text=planets, cp_max=5L, cp_title="Planets", cp_color=viridis(8))}
#' circlesplot(cp_vals=diameter, cp_text=planets, cp_max=5L, cp_title="Planets", cp_color=colors)
#'
#' # For coloring, you can also use viridis package:
#' library("viridis")
Expand Down Expand Up @@ -64,17 +64,24 @@ circlesplot <- function(cp_vals=NULL, cp_text=NULL, cp_max=10L, cp_line_width=2L

.plot_circlesplot <- function(df, cp_line_width, cp_title, cp_max, cp_title_size) {

par_old <- par(no.readonly = TRUE)
on.exit(par(par_old), add = TRUE)
diameter <- max(df$cp_vals)
count <- 0
x_pos <- 0
y_pos <- 5
y_pos_text <- y_pos -(diameter*1.5 + 3)
color_pos <- 1

par(cex.main = cp_title_size)
plot(0, 0, type = "n", xlim = c(- (2 + diameter), (cp_max * diameter) * 2), ylim = c( - (2.5* (ceiling(length(df$cp_vals) / cp_max) * diameter)), diameter *2), axes=FALSE, asp=1, main=cp_title, xlab="", ylab="")
par_old <- par(no.readonly = TRUE, fig=c(0, 1, 0, 1))

plot(0, 0, type = "n", xlim = c(- (2 + diameter), (cp_max * diameter) * 2), ylim = c( - (2.5* (ceiling(length(df$cp_vals) / cp_max) * diameter)), diameter *2), axes=FALSE, asp=1, xlab="", ylab="")

if(cp_max %% 2 == 0) {
text((cp_max / 2) * (x_pos + diameter * 2 + 1) - ((x_pos + diameter * 2 + 1) / 2), diameter*2 + y_pos, cp_title, cex=cp_title_size)
} else {
text((floor(cp_max / 2)) * (x_pos + diameter * 2 + 1), diameter*2 + y_pos, cp_title, cex=cp_title_size)
}

on.exit(par(par_old), add = TRUE)

for (item in df$cp_vals) {

Expand Down
10 changes: 5 additions & 5 deletions man/circlesplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf84420

Please sign in to comment.