knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This is a small example to illustrate the use of visualizations provided in ggradialbar
. The visualizations provided in ggradialbar
are meant for visualizing high-dimensional clusters and their evolution.
# pkgs <- c("tidyverse", "DataExplorer", "tidymodels", "MASS", "corrplot") # install.packages(pkgs) library(tidyverse) library(DataExplorer) library(tidymodels) library(MASS) library(corrplot) # install.packages("ggradialbar") # library(ggradialbar)
The Boston dataset contains Housing Values in suburbs of Boston. The dataframe has 506 rows and 14 columns. You can find the description of the features in the following link: https://www.rdocumentation.org/packages/MASS/versions/7.3-53.1/topics/Boston
data <- Boston # from MASS package str(data) summary(data)
The range of features varies so normalize variables using z-score normalization.
scaled_dataset <- scale(data, center = TRUE, scale = TRUE) scaled_dataset <- as_tibble(scaled_dataset) head(scaled_dataset)
kclust <- kmeans(scaled_dataset, centers = 3) summary(kclust)
data <- augment(kclust, scaled_dataset) # augment adds the point classifications to the original data set. head(data)
data <- data %>% pivot_longer(names_to = "x", values_to = "y", cols = -c(.cluster))
Assigning feature names to different groups based on their similar characteristics.
NOTE: This variable is added to be used for the group_names
parameter in ggradialbar
geoms.
For this example: we are assigning random names to groups.
data <- data %>% mutate(.gr_name = case_when(x == "crim" | x == "zn" ~ "random", x == "indus" | x == "chas" ~ "group", x == "nox" | x == "rm" ~ "names", x == "age" | x == "dis" ~ "show", x == "rad" | x == "tax" ~ "visualize", x == "ptratio" | x == "black" ~ "groups", x == "lstat" | x == "medv" ~ "features") ) %>% arrange(.cluster) head(data)
To illustrate how to visualize cluster evolution, we are using the data attached with the ggradialrbar
package.
#head(tidy_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.