Skip to content

Commit

Permalink
added example
Browse files Browse the repository at this point in the history
  • Loading branch information
sskorik01 committed Jan 4, 2024
1 parent 80a258c commit ddeb883
Show file tree
Hide file tree
Showing 18 changed files with 394,540 additions and 2 deletions.
36 changes: 36 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
output: github_document

---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand Down Expand Up @@ -87,6 +88,41 @@ readr::read_csv("data-raw/dictionary.csv", col_types = cols(.default = "c")) |>

## Example

### Visualizing Vegetable Distribution in Malawi Gardens
This code snippet utilizes rAmCharts4 in R to visualize vegetable diversity in Malawian gardens. By displaying the distribution of crops grown, it highlights how Malawians can self-provide a diverse range of vegetables, crucial for a balanced diet.
```{r}
library(dplyr)
library(tidyr)
library(rAmCharts4)
library(htmlwidgets)
chckapmalawi$vegetables_grown_in_garden <- gsub("Other \\(please specify\\)", "Other", chckapmalawi$vegetables_grown_in_garden)
split_data <- chckapmalawi |>
separate_rows(vegetables_grown_in_garden, sep = ",\\s*") |>
mutate(vegetables_grown_in_garden = trimws(vegetables_grown_in_garden)) |>
filter(vegetables_grown_in_garden != "")
vegetable_freq <- table(split_data$vegetables_grown_in_garden)
vegetable_freq_df <- as.data.frame(vegetable_freq)
names(vegetable_freq_df) <- c("Vegetable", "Frequency")
vegetable_freq_df$Percentage <- vegetable_freq_df$Frequency / sum(vegetable_freq_df$Frequency) * 100
chart <- amPieChart(
data = vegetable_freq_df,
category = "Vegetable",
value = "Frequency",
depth = 30,
legend = FALSE,
chartTitle = "Vegetables Grown in Garden (Malawi)",
animated = 1,
theme = "spiritedaway"
)
```
```{r, echo=FALSE, fig.cap="Screenshot of an interactive pie chart with rAmCharts4", out.width='75%'}
knitr::include_graphics("man/figures/vegetables_plot.png")
```

## License

Expand Down
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# chckapmalawi

<!-- badges: start -->

[![R-CMD-check](https://github.com/openwashdata/chckapmalawi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/openwashdata/chckapmalawi/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

This packages compiles insights from a Knowledge, Attitudes, and
Practices (KAP) Survey conducted by BASEflow for Waste Advisers in
Malawi, focusing on Community Health Centers (CHCs).
Practices (KAP) Survey conducted by [BASEflow](https://baseflowmw.org/)
for Waste Advisers in Malawi, focusing on Community Health Centers
(CHCs).

## Installation

Expand Down Expand Up @@ -198,6 +201,54 @@ chckapmalawi

## Example

### Visualizing Vegetable Distribution in Malawi Gardens

This code snippet utilizes rAmCharts4 in R to visualize vegetable
diversity in Malawian gardens. By displaying the distribution of crops
grown, it highlights how Malawians can self-provide a diverse range of
vegetables, crucial for a balanced diet.

``` r
library(dplyr)
library(tidyr)
library(rAmCharts4)
#> Warning: Paket 'rAmCharts4' wurde unter R Version 4.3.2 erstellt
library(htmlwidgets)

chckapmalawi$vegetables_grown_in_garden <- gsub("Other \\(please specify\\)", "Other", chckapmalawi$vegetables_grown_in_garden)

split_data <- chckapmalawi |>
separate_rows(vegetables_grown_in_garden, sep = ",\\s*") |>
mutate(vegetables_grown_in_garden = trimws(vegetables_grown_in_garden)) |>
filter(vegetables_grown_in_garden != "")

vegetable_freq <- table(split_data$vegetables_grown_in_garden)
vegetable_freq_df <- as.data.frame(vegetable_freq)
names(vegetable_freq_df) <- c("Vegetable", "Frequency")

vegetable_freq_df$Percentage <- vegetable_freq_df$Frequency / sum(vegetable_freq_df$Frequency) * 100

chart <- amPieChart(
data = vegetable_freq_df,
category = "Vegetable",
value = "Frequency",
depth = 30,
legend = FALSE,
chartTitle = "Vegetables Grown in Garden (Malawi)",
animated = 1,
theme = "spiritedaway"
)
```

<div class="figure">

<img src="man/figures/vegetables_plot.png" alt="Screenshot of an interactive pie chart with rAmCharts4" width="75%" />
<p class="caption">
Screenshot of an interactive pie chart with rAmCharts4
</p>

</div>

## License

Data are available as
Expand Down
Binary file added man/figures/README-unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/vegetables_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131,218 changes: 131,218 additions & 0 deletions plot.html

Large diffs are not rendered by default.

131,218 changes: 131,218 additions & 0 deletions utils/plot.html

Large diffs are not rendered by default.

Loading

0 comments on commit ddeb883

Please sign in to comment.