Skip to content

Commit

Permalink
added dumbbell example in vignette + area charts
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Jun 14, 2023
1 parent be187e3 commit 5587cdb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: apexcharter
Version: 0.4.0.9300
Version: 0.4.0.9400
Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library
Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'.
'Apexcharts' is a modern JavaScript charting library to build interactive charts and visualizations with simple API.
Expand Down
2 changes: 1 addition & 1 deletion man/apex.Rd

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

84 changes: 79 additions & 5 deletions vignettes/apexcharter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,62 @@ apex(data = economics_long, type = "line", mapping = aes(x = date, y = value01,
```


## Area charts

Create area charts with `type = "area"`:

```{r area}
apex(data = economics_long, type = "area", mapping = aes(x = date, y = value01, fill = variable)) %>%
ax_yaxis(decimalsInFloat = 2) %>% # number of decimals to keep
ax_chart(stacked = TRUE) %>%
ax_yaxis(max = 4, tickAmount = 4)
data("eco2mix", package = "apexcharter")
apex(eco2mix, aes(datetime, production, fill = source), type = "area") %>%
ax_chart(animations = list(enabled = FALSE), stacked = TRUE) %>%
ax_stroke(width = 1) %>%
ax_fill(opacity = 1, type = "solid") %>%
ax_tooltip(x = list(format = "dd MMM, HH:mm")) %>%
ax_yaxis(labels = list(formatter = format_num("~", suffix = "MW"))) %>%
ax_colors_manual(
list(
"bioenergies" = "#156956",
"fuel" = "#80549f",
"coal" = "#a68832",
"solar" = "#d66b0d",
"gas" = "#f20809",
"wind" = "#72cbb7",
"hydraulic" = "#2672b0",
"nuclear" = "#e4a701",
"pumping" = "#0e4269"
)
) %>%
ax_labs(
title = "Electricity generation by sector in France",
subtitle = "Data from \u00e9CO\u2082mix"
)
```


You can create ribbon charts using `ymin` and `ymax` aesthetics :

```{r ribbon}
data("temperatures", package = "apexcharter")
apex(
temperatures,
aes(x = date, ymin = low, ymax = high),
type = "rangeArea",
serie_name = "Low/High (2018-2021)"
) %>%
add_line(aes(date, `2023`)) %>%
ax_chart(animations = list(enabled = FALSE)) %>%
ax_yaxis(tickAmount = 7, labels = list(formatter = format_num("~", suffix = "°C"))) %>%
ax_colors(c("#8485854D", "#FF0000")) %>%
ax_stroke(width = c(1, 2)) %>%
ax_fill(opacity = 1, type = "solid") %>%
ax_labs(
title = "Temperatures in 2023 with range from 2018 to 2021",
subtitle = "Data from ENEDIS"
)
```




Expand All @@ -118,7 +164,7 @@ apex(data = mtcars, type = "scatter", mapping = aes(x = wt, y = mpg, z = scales:



## Pie charts
## Pie & donut charts

Simple pie charts can be created with:

Expand All @@ -131,6 +177,12 @@ poll <- data.frame(
apex(data = poll, type = "pie", mapping = aes(x = answer, y = n))
```

It's also possible to make donut chart:

```{r donut}
apex(data = poll, type = "donut", mapping = aes(x = answer, y = n))
```



## Radial charts
Expand Down Expand Up @@ -257,3 +309,25 @@ apex(mpg, aes(hwy, class), "boxplot") %>%
ax_stroke(colors = list("#2A5769"))
```


## Dumbbell charts

Create Dumbbell chart with:

```{r dumbbell}
data("life_expec", package = "apexcharter")
apex(life_expec, aes(country, x = `1972`, xend = `2007`), type = "dumbbell") %>%
ax_plotOptions(
bar = bar_opts(
dumbbellColors = list(list("#3d85c6", "#fb6003"))
)
) %>%
ax_colors("#BABABA") %>%
ax_labs(
title = "Life expectancy : 1972 vs. 2007",
subtitle = "Data from Gapminder dataset",
x = "Life expectancy at birth, in years"
)
```

0 comments on commit 5587cdb

Please sign in to comment.