knitr::opts_chunk$set(
  collapse = TRUE, warning = FALSE, message = FALSE, fig.align='center', fig.width=7, fig.height=5,
  comment = "#>"
)

Introduction

Used to compare the position or performance of multiple items with respect to each other. Actual values matters somewhat less than the ranking.

Lollipop

Lollipop chart sebenarnya hampir sama dengan bar chart. Namun salah satu kelebihannya adalah plot menjadi tidak terlalu penuh, karena direprsentasikan dengan point dan garis saja. Berikut adalah contohnya.

library(dataplot)
library(ggplot2)

df <- data.frame(
  "brand" = c("Samsung", "Huawei", "Apple", "Xiaomi", "OPPO"),
  "share" = c(10, 30, 20, 35, 5)
)

plot_lollipop(data = df, x = "brand", y = "share",
              title = "Lorem Ipsum is simply dummy text",
              subtitle = "Contrary to popular belief, Lorem Ipsum is not simply random text",
              data_source = "www.kedata.online"
              )

Dumbbell Plot

Dumbbell charts are a great tool if you wish to:

  1. Visualize relative positions (like growth and decline) between two points in time.
  2. Compare distance between two categories. In order to get the correct ordering of the dumbbells, the Y variable should be a factor and the levels of the factor variable should be in the same order as it should appear in the plot.
library(dataplot)

s <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")
s$School <- factor(s$School, levels = s$School[order(s$Men)])

plot_dumbbell(data = s,
              cat = "School",
              x1 = "Women",
              x2 = "Men",
              size = 3,
              x_title = "Salary",
              y_title = "School",
              title = "Gender earnings disparity",
              subtitle = "Gender earnings disparity from Women VS Men based on University",
              data_source = "www.kedata.online")


eppofahmi/dataplot documentation built on Jan. 22, 2025, 1:14 a.m.