Nama : Ahmad Fadhli Dzilikrom Nim : 220605110078 kelas : A Mata kuliah : Linear Algebra Dosen pengampuh : Prof. Dr. Muhammad Suhartono, M.Kom Jurusan : Teknik Informatika Fakultas : Sains dan Teknologi Universitas : Maulana Malik Ibrahim Malang — Untuk membuat Dumbbell Plot di R menggunakan ggplot2, kita menggunakan fungsi geom_dumbbell().

ylabel <- c("first","second","third")
x1 <- c(1,2,3)
x2 <- c(4,3,5)
datamain <- data.frame(ylabel,x1,x2)

library(ggplot2)
library(ggalt)
## Registered S3 methods overwritten by 'ggalt':
##   method                  from   
##   grid.draw.absoluteGrob  ggplot2
##   grobHeight.absoluteGrob ggplot2
##   grobWidth.absoluteGrob  ggplot2
##   grobX.absoluteGrob      ggplot2
##   grobY.absoluteGrob      ggplot2
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
ggplot() + geom_dumbbell(data = datamain,
                        aes(y = ylabel,
                            x = x1,
                            xend = x2),
                        size = 1.5)
## Warning: Using the `size` aesthetic with geom_segment was deprecated in ggplot2 3.4.0.
## ℹ Please use the `linewidth` aesthetic instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ylabel <- c("first","second","third")
x1 <- c(1,2,3)
x2 <- c(4,3,5)
datamain <- data.frame(ylabel,x1,x2)

library(ggplot2)
library(ggalt)
library(tidyverse)

ggplot() + geom_dumbbell(data = datamain,
                        aes(y = ylabel,
                            x = x1,
                            xend = x2),
                        size = 1.5,
                        size_x = 5,
                        size_xend = 9)

ylabel <- c("first","second","third",
            "fourth","fifth","Sixth")
x1 <- c(1,2,4,5,3,2)
x2 <- c(4,3,6,7,5,4)

datamain <- data.frame(ylabel,x1,x2)

library(ggplot2)
library(ggalt)  
library(tidyverse)

ggplot() +
geom_dumbbell(data = datamain, aes(y = ylabel,
                                    x = x1,
                                    xend = x2),
            size = 1.5, color = "purple", size_x = 7,
            size_xend = 7, colour_x = "green",
            colour_xend = "red")