remove dplyr from suggests
This commit is contained in:
parent
63db3566fb
commit
3e85bd477a
|
@ -24,7 +24,6 @@ Imports:
|
|||
shiny (>= 1.1.0)
|
||||
Suggests:
|
||||
testthat,
|
||||
dplyr,
|
||||
knitr,
|
||||
scales,
|
||||
rmarkdown,
|
||||
|
|
|
@ -134,10 +134,9 @@ events_opts <- function(click = NULL,
|
|||
#'
|
||||
#' @examples
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' apex(count(mpg, manufacturer), aes(manufacturer, n)) %>%
|
||||
#' apex(mpg, aes(manufacturer)) %>%
|
||||
#' ax_plotOptions(
|
||||
#' bar = bar_opts(
|
||||
#' endingShape = "rounded",
|
||||
|
@ -320,11 +319,9 @@ radialBar_opts <- function(size = NULL,
|
|||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' apex(count(mpg, cyl), aes(cyl, n), type = "donut") %>%
|
||||
#' apex(mpg, aes(cyl), type = "donut") %>%
|
||||
#' ax_plotOptions(
|
||||
#' pie = pie_opts(
|
||||
#' donut = list(size = "90%", background = "#BABABA")
|
||||
|
|
|
@ -198,13 +198,12 @@ ax_chart <- function(ax,
|
|||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("diamonds", package = "ggplot2")
|
||||
#'
|
||||
#' # Stack bar type
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut),
|
||||
#' mapping = aes(x = cut, y = n)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = cut)
|
||||
#' ) %>%
|
||||
#' ax_plotOptions(
|
||||
#' bar = bar_opts(endingShape = "rounded", columnWidth = "10%")
|
||||
|
@ -212,8 +211,8 @@ ax_chart <- function(ax,
|
|||
#'
|
||||
#' # Pie
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut),
|
||||
#' mapping = aes(x = cut, y = n),
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = cut),
|
||||
#' type = "pie"
|
||||
#' ) %>%
|
||||
#' ax_plotOptions(
|
||||
|
@ -254,22 +253,20 @@ ax_plotOptions <- function(ax,
|
|||
#' @note See \url{https://apexcharts.com/docs/options/colors/}
|
||||
#'
|
||||
#' @examples
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' data("diamonds", package = "ggplot2")
|
||||
#'
|
||||
#' # Change default color(s)
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut),
|
||||
#' mapping = aes(x = cut, y = n)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = cut)
|
||||
#' ) %>%
|
||||
#' ax_colors("#F7D358")
|
||||
#'
|
||||
#'
|
||||
#' library(scales)
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut, color),
|
||||
#' mapping = aes(x = cut, y = n, fill = color)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = cut, fill = color)
|
||||
#' ) %>%
|
||||
#' ax_colors(brewer_pal(palette = "Set2")(7))
|
||||
ax_colors <- function(ax, ...) {
|
||||
|
@ -300,13 +297,12 @@ ax_colors <- function(ax, ...) {
|
|||
#' @note See \url{https://apexcharts.com/docs/options/datalabels/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("diamonds", package = "ggplot2")
|
||||
#'
|
||||
#' # Add data labels
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut),
|
||||
#' mapping = aes(x = cut, y = n)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = cut)
|
||||
#' ) %>%
|
||||
#' ax_dataLabels(enabled = TRUE)
|
||||
ax_dataLabels <- function(ax,
|
||||
|
@ -341,13 +337,12 @@ ax_dataLabels <- function(ax,
|
|||
#' @note See \url{https://apexcharts.com/docs/options/fill/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("diamonds", package = "ggplot2")
|
||||
#'
|
||||
#' # Use a pattern to fill bars
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut, color),
|
||||
#' mapping = aes(x = color, y = n, fill = cut)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = color, fill = cut)
|
||||
#' ) %>%
|
||||
#' ax_fill(
|
||||
#' type = "pattern",
|
||||
|
@ -407,20 +402,19 @@ ax_fill <- function(ax,
|
|||
#' @note See \url{https://apexcharts.com/docs/options/grid/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' # Hide Y-axis and gridelines
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer)
|
||||
#' ) %>%
|
||||
#' ax_grid(show = FALSE)
|
||||
#'
|
||||
#' # just grid lines
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer)
|
||||
#' ) %>%
|
||||
#' ax_grid(yaxis = list(lines = list(show = FALSE)))
|
||||
#'
|
||||
|
@ -522,20 +516,19 @@ ax_labels2 <- function(ax, labels) {
|
|||
#' @note See \url{https://apexcharts.com/docs/options/legend/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' # Legend position
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer, year),
|
||||
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer, fill = year)
|
||||
#' ) %>%
|
||||
#' ax_legend(position = "right")
|
||||
#'
|
||||
#' # hide legend
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer, year),
|
||||
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer, fill = year)
|
||||
#' ) %>%
|
||||
#' ax_legend(show = FALSE)
|
||||
ax_legend <- function(ax,
|
||||
|
@ -650,13 +643,12 @@ ax_noData <- function(ax,
|
|||
#' @note See \url{https://apexcharts.com/docs/options/responsive/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' # Open in browser and resize window
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer, year),
|
||||
#' mapping = aes(x = manufacturer, y = n, fill = year),
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer, fill = year),
|
||||
#' type = "bar"
|
||||
#' ) %>%
|
||||
#' ax_legend(position = "right") %>%
|
||||
|
@ -737,13 +729,12 @@ ax_series2 <- function(ax, l) {
|
|||
#' @note See \url{https://apexcharts.com/docs/options/states/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' # Inverse effect on hover
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n),
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer),
|
||||
#' type = "bar"
|
||||
#' ) %>%
|
||||
#' ax_states(
|
||||
|
@ -930,20 +921,19 @@ ax_stroke <- function(ax,
|
|||
#' @note See \url{https://apexcharts.com/docs/options/tooltip/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' # Hide tooltip
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer, year),
|
||||
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer, fill = year)
|
||||
#' ) %>%
|
||||
#' ax_tooltip(enabled = FALSE)
|
||||
#'
|
||||
#' # Share between series
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer, year),
|
||||
#' mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer, fill = year)
|
||||
#' ) %>%
|
||||
#' ax_tooltip(shared = TRUE)
|
||||
#'
|
||||
|
@ -1006,27 +996,26 @@ ax_tooltip <- function(ax,
|
|||
#' @note See \url{https://apexcharts.com/docs/options/xaxis/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#'
|
||||
#' # X axis title
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer)
|
||||
#' ) %>%
|
||||
#' ax_xaxis(title = list(text = "Car's manufacturer"))
|
||||
#'
|
||||
#' # force labels to rotate and increase height
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer)
|
||||
#' ) %>%
|
||||
#' ax_xaxis(labels = list(rotateAlways = TRUE, maxHeight = 180))
|
||||
#'
|
||||
#' # force to not rotate
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer)
|
||||
#' ) %>%
|
||||
#' ax_xaxis(labels = list(rotate = 0, trim = FALSE))
|
||||
#'
|
||||
|
@ -1193,28 +1182,27 @@ ax_yaxis2 <- function(ax, ...) {
|
|||
#' @note See \url{https://apexcharts.com/docs/options/theme/}
|
||||
#'
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' data("mpg", package = "ggplot2")
|
||||
#' data("diamonds", package = "ggplot2")
|
||||
#'
|
||||
#' # Dark mode
|
||||
#' apex(
|
||||
#' data = count(mpg, manufacturer),
|
||||
#' mapping = aes(x = manufacturer, y = n)
|
||||
#' data = mpg,
|
||||
#' mapping = aes(x = manufacturer)
|
||||
#' ) %>%
|
||||
#' ax_theme(mode = "dark")
|
||||
#'
|
||||
#' # Use predefined palette (1 to 10)
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut, color),
|
||||
#' mapping = aes(x = color, y = n, fill = cut)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = color, fill = cut)
|
||||
#' ) %>%
|
||||
#' ax_theme(palette = "palette2")
|
||||
#'
|
||||
#' # monochrome palette
|
||||
#' apex(
|
||||
#' data = count(diamonds, cut, color),
|
||||
#' mapping = aes(x = color, y = n, fill = cut)
|
||||
#' data = diamonds,
|
||||
#' mapping = aes(x = color, fill = cut)
|
||||
#' ) %>%
|
||||
#' ax_theme(monochrome = list(enabled = TRUE, color = "#0B6121"))
|
||||
ax_theme <- function(ax,
|
||||
|
|
10
README.md
10
README.md
|
@ -39,11 +39,8 @@ Use `apex` function to quickly create visualizations :
|
|||
|
||||
```r
|
||||
library(apexcharter)
|
||||
|
||||
data("mpg", package = "ggplot2")
|
||||
n_manufac <- dplyr::count(mpg, manufacturer)
|
||||
|
||||
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
|
||||
apex(data = mpg, type = "bar", mapping = aes(manufacturer))
|
||||
```
|
||||
![](man/figures/apex-bar.png)
|
||||
|
||||
|
@ -65,7 +62,6 @@ All methods from ApexCharts are available with function like `ax_*` compatible w
|
|||
```r
|
||||
library(apexcharter)
|
||||
data(mpg, package = "ggplot2")
|
||||
n_manufac <- dplyr::count(mpg, manufacturer)
|
||||
|
||||
apexchart() %>%
|
||||
ax_chart(type = "bar") %>%
|
||||
|
@ -84,10 +80,10 @@ apexchart() %>%
|
|||
) %>%
|
||||
ax_series(list(
|
||||
name = "Count",
|
||||
data = n_manufac$n
|
||||
data = tapply(mpg$manufacturer, mpg$manufacturer, length)
|
||||
)) %>%
|
||||
ax_colors("#112446") %>%
|
||||
ax_xaxis(categories = n_manufac$manufacturer) %>%
|
||||
ax_xaxis(categories = unique(mpg$manufacturer)) %>%
|
||||
ax_title(text = "Number of models") %>%
|
||||
ax_subtitle(text = "Data from ggplot2")
|
||||
```
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(apexcharter)
|
||||
|
||||
# make a barchart with a frequency table
|
||||
data("mpg", package = "ggplot2")
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n),
|
||||
type = "bar"
|
||||
)
|
||||
apex(mpg, aes(manufacturer), type = "bar")
|
||||
|
||||
|
||||
# timeseries
|
||||
data("economics", package = "ggplot2")
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
library(dplyr)
|
||||
library(apexcharter)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
## Stack bar type
|
||||
# default is dodge
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
)
|
||||
|
||||
# stack
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) %>%
|
||||
ax_chart(stacked = TRUE)
|
||||
|
||||
# stack filled
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) %>%
|
||||
ax_chart(stacked = TRUE, stackType = "100%")
|
||||
|
||||
|
@ -29,8 +29,8 @@ apex(
|
|||
|
||||
# Hide the toolbar
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) %>%
|
||||
ax_chart(toolbar = list(show = FALSE))
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
library(apexcharter)
|
||||
library(dplyr)
|
||||
data("economics_long", package = "ggplot2")
|
||||
|
||||
eco <- economics_long %>%
|
||||
filter(variable %in% c("pce", "pop")) %>%
|
||||
mutate(value = round(value))
|
||||
subset(variable %in% c("pce", "pop")) %>%
|
||||
transform(value = round(value))
|
||||
|
||||
# add second y-axis
|
||||
apex(eco, aes(x = date, y = value, color = variable), type = "line") %>%
|
||||
|
|
|
@ -5,8 +5,10 @@ data("mpg", package = "ggplot2")
|
|||
### No grouping
|
||||
|
||||
# Both charts should be equivalent
|
||||
n_manufac <- dplyr::count(mpg, manufacturer)
|
||||
apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = n))
|
||||
n_manufac <- as.data.frame(table(
|
||||
manufacturer = mpg$manufacturer
|
||||
))
|
||||
apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = Freq))
|
||||
|
||||
apex(data = mpg, type = "column", mapping = aes(x = manufacturer))
|
||||
|
||||
|
@ -14,8 +16,19 @@ apex(data = mpg, type = "column", mapping = aes(x = manufacturer))
|
|||
### With groups
|
||||
|
||||
# Both charts should be equivalent
|
||||
n_manufac_year <- dplyr::count(mpg, manufacturer, year)
|
||||
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year))
|
||||
n_manufac_year <- as.data.frame(table(
|
||||
manufacturer = mpg$manufacturer,
|
||||
year = mpg$year
|
||||
))
|
||||
apex(
|
||||
data = n_manufac_year,
|
||||
type = "column",
|
||||
mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
)
|
||||
|
||||
apex(data = mpg, type = "column", mapping = aes(x = manufacturer, fill = year))
|
||||
apex(
|
||||
data = mpg,
|
||||
type = "column",
|
||||
mapping = aes(x = manufacturer, fill = year)
|
||||
)
|
||||
|
||||
|
|
|
@ -58,16 +58,12 @@ data, mapping and type of chart.
|
|||
}
|
||||
\examples{
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(apexcharter)
|
||||
|
||||
# make a barchart with a frequency table
|
||||
data("mpg", package = "ggplot2")
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n),
|
||||
type = "bar"
|
||||
)
|
||||
apex(mpg, aes(manufacturer), type = "bar")
|
||||
|
||||
|
||||
# timeseries
|
||||
data("economics", package = "ggplot2")
|
||||
|
|
|
@ -82,27 +82,27 @@ A \code{apexcharts} \code{htmlwidget} object.
|
|||
Chart parameters
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
library(apexcharter)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
## Stack bar type
|
||||
# default is dodge
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
)
|
||||
|
||||
# stack
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) \%>\%
|
||||
ax_chart(stacked = TRUE)
|
||||
|
||||
# stack filled
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) \%>\%
|
||||
ax_chart(stacked = TRUE, stackType = "100\%")
|
||||
|
||||
|
@ -113,8 +113,8 @@ apex(
|
|||
|
||||
# Hide the toolbar
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) \%>\%
|
||||
ax_chart(toolbar = list(show = FALSE))
|
||||
|
||||
|
|
|
@ -21,22 +21,20 @@ Colors
|
|||
See \url{https://apexcharts.com/docs/options/colors/}
|
||||
}
|
||||
\examples{
|
||||
|
||||
library(dplyr)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Change default color(s)
|
||||
apex(
|
||||
data = count(diamonds, cut),
|
||||
mapping = aes(x = cut, y = n)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut)
|
||||
) \%>\%
|
||||
ax_colors("#F7D358")
|
||||
|
||||
|
||||
library(scales)
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut, fill = color)
|
||||
) \%>\%
|
||||
ax_colors(brewer_pal(palette = "Set2")(7))
|
||||
}
|
||||
|
|
|
@ -46,13 +46,12 @@ Labels on data
|
|||
See \url{https://apexcharts.com/docs/options/datalabels/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Add data labels
|
||||
apex(
|
||||
data = count(diamonds, cut),
|
||||
mapping = aes(x = cut, y = n)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut)
|
||||
) \%>\%
|
||||
ax_dataLabels(enabled = TRUE)
|
||||
}
|
||||
|
|
|
@ -43,13 +43,12 @@ Fill property
|
|||
See \url{https://apexcharts.com/docs/options/fill/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Use a pattern to fill bars
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = color, y = n, fill = cut)
|
||||
data = diamonds,
|
||||
mapping = aes(x = color, fill = cut)
|
||||
) \%>\%
|
||||
ax_fill(
|
||||
type = "pattern",
|
||||
|
|
|
@ -51,20 +51,19 @@ Add grids on chart
|
|||
See \url{https://apexcharts.com/docs/options/grid/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# Hide Y-axis and gridelines
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer)
|
||||
) \%>\%
|
||||
ax_grid(show = FALSE)
|
||||
|
||||
# just grid lines
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer)
|
||||
) \%>\%
|
||||
ax_grid(yaxis = list(lines = list(show = FALSE)))
|
||||
|
||||
|
|
|
@ -83,20 +83,19 @@ Legend properties
|
|||
See \url{https://apexcharts.com/docs/options/legend/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# Legend position
|
||||
apex(
|
||||
data = count(mpg, manufacturer, year),
|
||||
mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer, fill = year)
|
||||
) \%>\%
|
||||
ax_legend(position = "right")
|
||||
|
||||
# hide legend
|
||||
apex(
|
||||
data = count(mpg, manufacturer, year),
|
||||
mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer, fill = year)
|
||||
) \%>\%
|
||||
ax_legend(show = FALSE)
|
||||
}
|
||||
|
|
|
@ -36,13 +36,12 @@ A \code{apexcharts} \code{htmlwidget} object.
|
|||
Specific options for chart
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Stack bar type
|
||||
apex(
|
||||
data = count(diamonds, cut),
|
||||
mapping = aes(x = cut, y = n)
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut)
|
||||
) \%>\%
|
||||
ax_plotOptions(
|
||||
bar = bar_opts(endingShape = "rounded", columnWidth = "10\%")
|
||||
|
@ -50,8 +49,8 @@ apex(
|
|||
|
||||
# Pie
|
||||
apex(
|
||||
data = count(diamonds, cut),
|
||||
mapping = aes(x = cut, y = n),
|
||||
data = diamonds,
|
||||
mapping = aes(x = cut),
|
||||
type = "pie"
|
||||
) \%>\%
|
||||
ax_plotOptions(
|
||||
|
|
|
@ -21,13 +21,12 @@ Responsive options
|
|||
See \url{https://apexcharts.com/docs/options/responsive/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# Open in browser and resize window
|
||||
apex(
|
||||
data = count(mpg, manufacturer, year),
|
||||
mapping = aes(x = manufacturer, y = n, fill = year),
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer, fill = year),
|
||||
type = "bar"
|
||||
) \%>\%
|
||||
ax_legend(position = "right") \%>\%
|
||||
|
|
|
@ -27,13 +27,12 @@ Charts' states
|
|||
See \url{https://apexcharts.com/docs/options/states/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# Inverse effect on hover
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n),
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer),
|
||||
type = "bar"
|
||||
) \%>\%
|
||||
ax_states(
|
||||
|
|
|
@ -27,28 +27,27 @@ Theme for charts
|
|||
See \url{https://apexcharts.com/docs/options/theme/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Dark mode
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer)
|
||||
) \%>\%
|
||||
ax_theme(mode = "dark")
|
||||
|
||||
# Use predefined palette (1 to 10)
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = color, y = n, fill = cut)
|
||||
data = diamonds,
|
||||
mapping = aes(x = color, fill = cut)
|
||||
) \%>\%
|
||||
ax_theme(palette = "palette2")
|
||||
|
||||
# monochrome palette
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = color, y = n, fill = cut)
|
||||
data = diamonds,
|
||||
mapping = aes(x = color, fill = cut)
|
||||
) \%>\%
|
||||
ax_theme(monochrome = list(enabled = TRUE, color = "#0B6121"))
|
||||
}
|
||||
|
|
|
@ -69,20 +69,19 @@ Tooltip options
|
|||
See \url{https://apexcharts.com/docs/options/tooltip/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# Hide tooltip
|
||||
apex(
|
||||
data = count(mpg, manufacturer, year),
|
||||
mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer, fill = year)
|
||||
) \%>\%
|
||||
ax_tooltip(enabled = FALSE)
|
||||
|
||||
# Share between series
|
||||
apex(
|
||||
data = count(mpg, manufacturer, year),
|
||||
mapping = aes(x = manufacturer, y = n, fill = year)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer, fill = year)
|
||||
) \%>\%
|
||||
ax_tooltip(shared = TRUE)
|
||||
|
||||
|
|
|
@ -68,27 +68,26 @@ X-axis options
|
|||
See \url{https://apexcharts.com/docs/options/xaxis/}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
# X axis title
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer)
|
||||
) \%>\%
|
||||
ax_xaxis(title = list(text = "Car's manufacturer"))
|
||||
|
||||
# force labels to rotate and increase height
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer)
|
||||
) \%>\%
|
||||
ax_xaxis(labels = list(rotateAlways = TRUE, maxHeight = 180))
|
||||
|
||||
# force to not rotate
|
||||
apex(
|
||||
data = count(mpg, manufacturer),
|
||||
mapping = aes(x = manufacturer, y = n)
|
||||
data = mpg,
|
||||
mapping = aes(x = manufacturer)
|
||||
) \%>\%
|
||||
ax_xaxis(labels = list(rotate = 0, trim = FALSE))
|
||||
|
||||
|
|
|
@ -19,12 +19,11 @@ Secondary Y-axis options
|
|||
}
|
||||
\examples{
|
||||
library(apexcharter)
|
||||
library(dplyr)
|
||||
data("economics_long", package = "ggplot2")
|
||||
|
||||
eco <- economics_long \%>\%
|
||||
filter(variable \%in\% c("pce", "pop")) \%>\%
|
||||
mutate(value = round(value))
|
||||
subset(variable \%in\% c("pce", "pop")) \%>\%
|
||||
transform(value = round(value))
|
||||
|
||||
# add second y-axis
|
||||
apex(eco, aes(x = date, y = value, color = variable), type = "line") \%>\%
|
||||
|
|
|
@ -43,10 +43,9 @@ See \url{https://apexcharts.com/docs/options/plotoptions/bar/}.
|
|||
}
|
||||
\examples{
|
||||
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
apex(count(mpg, manufacturer), aes(manufacturer, n)) \%>\%
|
||||
apex(mpg, aes(manufacturer)) \%>\%
|
||||
ax_plotOptions(
|
||||
bar = bar_opts(
|
||||
endingShape = "rounded",
|
||||
|
|
|
@ -40,11 +40,9 @@ Use these options in \code{\link{ax_plotOptions}}.
|
|||
See \url{https://apexcharts.com/docs/options/plotoptions/pie/}.
|
||||
}
|
||||
\examples{
|
||||
|
||||
library(dplyr)
|
||||
data("mpg", package = "ggplot2")
|
||||
|
||||
apex(count(mpg, cyl), aes(cyl, n), type = "donut") \%>\%
|
||||
apex(mpg, aes(cyl), type = "donut") \%>\%
|
||||
ax_plotOptions(
|
||||
pie = pie_opts(
|
||||
donut = list(size = "90\%", background = "#BABABA")
|
||||
|
|
|
@ -18,13 +18,12 @@ knitr::opts_chunk$set(
|
|||
|
||||
The objective of this vignette is to show how to quickly build data visualizations with the ApexCharts JavaScript library, as well as to give an overview of the different graphics available.
|
||||
|
||||
Data used are from `ggplot2` package, data manipulation will be done with the `dplyr` package.
|
||||
Data used are from `ggplot2` package.
|
||||
|
||||
|
||||
```{r message=FALSE, warning=FALSE}
|
||||
library(ggplot2)
|
||||
library(scales)
|
||||
library(dplyr)
|
||||
library(apexcharter)
|
||||
```
|
||||
|
||||
|
@ -35,30 +34,27 @@ Simple bar charts can be created with:
|
|||
|
||||
```{r column}
|
||||
data("mpg")
|
||||
n_manufac <- count(mpg, manufacturer)
|
||||
|
||||
apex(data = n_manufac, type = "column", mapping = aes(x = manufacturer, y = n))
|
||||
apex(data = mpg, type = "column", mapping = aes(x = manufacturer))
|
||||
```
|
||||
|
||||
Flipping coordinates can be done by using `type = "bar"`:
|
||||
|
||||
```{r bar}
|
||||
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
|
||||
apex(data = mpg, type = "bar", mapping = aes(x = manufacturer))
|
||||
```
|
||||
|
||||
|
||||
To create a dodge bar charts, use aesthetic `fill` :
|
||||
|
||||
```{r dodge-bar}
|
||||
n_manufac_year <- count(mpg, manufacturer, year)
|
||||
|
||||
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year))
|
||||
apex(data = mpg, type = "column", mapping = aes(x = manufacturer, fill = year))
|
||||
```
|
||||
|
||||
For stacked bar charts, specify option `stacked` in `ax_chart` :
|
||||
|
||||
```{r stacked-bar}
|
||||
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = n, fill = year)) %>%
|
||||
apex(data = mpg, type = "column", mapping = aes(x = manufacturer, fill = year)) %>%
|
||||
ax_chart(stacked = TRUE)
|
||||
```
|
||||
|
||||
|
@ -70,7 +66,6 @@ Simple line charts can be created with (works with `character`, `Date` or `POSIX
|
|||
|
||||
```{r line}
|
||||
data("economics")
|
||||
economics <- tail(economics, 100)
|
||||
|
||||
apex(data = economics, type = "line", mapping = aes(x = date, y = uempmed))
|
||||
```
|
||||
|
@ -80,9 +75,6 @@ To represent several lines, use a `data.frame` in long format and the `group` ae
|
|||
|
||||
```{r lines}
|
||||
data("economics_long")
|
||||
economics_long <- economics_long %>%
|
||||
group_by(variable) %>%
|
||||
slice((n()-100):n())
|
||||
|
||||
apex(data = economics_long, type = "line", mapping = aes(x = date, y = value01, group = variable)) %>%
|
||||
ax_yaxis(decimalsInFloat = 2) # number of decimals to keep
|
||||
|
@ -210,14 +202,14 @@ apex(mtcars, aes(rownames(mtcars), mpg), type = "polarArea") %>%
|
|||
Create a heatmap with :
|
||||
|
||||
```{r heatmap}
|
||||
txhousing2 <- txhousing %>%
|
||||
filter(city %in% head(unique(city)), year %in% c(2000, 2001)) %>%
|
||||
rename(val_med = median)
|
||||
# create some data
|
||||
sales <- expand.grid(year = 2010:2020, month = month.name)
|
||||
sales$value <- sample(-10:30, nrow(sales), TRUE)
|
||||
|
||||
apex(
|
||||
data = txhousing2,
|
||||
data = sales,
|
||||
type = "heatmap",
|
||||
mapping = aes(x = date, y = city, fill = scales::rescale(val_med))
|
||||
mapping = aes(x = year, y = month, fill = value)
|
||||
) %>%
|
||||
ax_dataLabels(enabled = FALSE) %>%
|
||||
ax_colors("#008FFB")
|
||||
|
@ -230,9 +222,8 @@ Create a treemap with:
|
|||
|
||||
```{r treemap}
|
||||
data("mpg", package = "ggplot2")
|
||||
n_manufac <- dplyr::count(mpg, manufacturer)
|
||||
|
||||
apex(n_manufac, aes(x = manufacturer, y = n), "treemap")
|
||||
apex(mpg, aes(x = manufacturer), "treemap")
|
||||
```
|
||||
|
||||
|
||||
|
@ -242,6 +233,7 @@ Create a candlestick chart with:
|
|||
|
||||
```{r}
|
||||
data("candles", package = "apexcharter")
|
||||
|
||||
apex(
|
||||
candles,
|
||||
aes(x = datetime, open = open, close = close, low = low, high = high),
|
||||
|
|
|
@ -21,10 +21,8 @@ Packages and data used below:
|
|||
|
||||
```{r message=FALSE, warning=FALSE}
|
||||
library(apexcharter)
|
||||
library(dplyr)
|
||||
|
||||
data("diamonds", package = "ggplot2")
|
||||
n_cut <- count(diamonds, cut)
|
||||
```
|
||||
|
||||
|
||||
|
@ -33,7 +31,7 @@ n_cut <- count(diamonds, cut)
|
|||
You can set title, subtitle and axis' titles at once with `ax_labs()`:
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_labs(
|
||||
title = "Cut distribution",
|
||||
subtitle = "Data from ggplot2",
|
||||
|
@ -49,14 +47,14 @@ If you more control (font size, alignment, ...), you can use `ax_title()`, `ax_s
|
|||
### Title
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_title(text = "Cut distribution")
|
||||
```
|
||||
|
||||
You can set some options, for example:
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_title(
|
||||
text = "Cut distribution",
|
||||
align = "center",
|
||||
|
@ -71,7 +69,7 @@ Full list of parameters is available here : https://apexcharts.com/docs/options/
|
|||
### Subtitle
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_title(text = "Cut distribution") %>%
|
||||
ax_subtitle(text = "Data from ggplot2")
|
||||
```
|
||||
|
@ -79,7 +77,7 @@ apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
|||
With same options than for title:
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_title(
|
||||
text = "Cut distribution",
|
||||
align = "center",
|
||||
|
@ -98,7 +96,7 @@ Full list of parameters is available here : https://apexcharts.com/docs/options/
|
|||
### Axis title
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_yaxis(title = list(text = "Count")) %>%
|
||||
ax_xaxis(title = list(text = "Cut"))
|
||||
```
|
||||
|
@ -106,7 +104,7 @@ apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
|||
With some options:
|
||||
|
||||
```{r}
|
||||
apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
||||
apex(data = diamonds, type = "column", mapping = aes(x = cut)) %>%
|
||||
ax_yaxis(title = list(
|
||||
text = "Count",
|
||||
style = list(fontSize = "14px", color = "#BDBDBD")
|
||||
|
@ -125,17 +123,12 @@ apex(data = n_cut, type = "column", mapping = aes(x = cut, y = n)) %>%
|
|||
|
||||
```{r message=FALSE, warning=FALSE}
|
||||
library(apexcharter)
|
||||
library(dplyr)
|
||||
|
||||
## economics dataset from ggplot2
|
||||
data("economics", package = "ggplot2")
|
||||
economics <- tail(economics, 50)
|
||||
|
||||
data("economics_long", package = "ggplot2")
|
||||
economics_long <- economics_long %>%
|
||||
filter(variable %in% c("pce", "pop")) %>%
|
||||
group_by(variable) %>%
|
||||
slice(tail(row_number(), 20))
|
||||
economics <- tail(economics, 50)
|
||||
economics_long <- subset(economics_long, date >= "2010-01-01")
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue