Building a Butterfly plot in R

Butterfly plot
library(plotly)
library(dplyr)
library(tidyr)
dat <- data.frame(
a = c("A", "B", "C"),
b = c(1,2,3),
b1 = c(8,9,10),
c = c(1,2,3),
c1 = c(8,9,10))
b <- dat %>% plot_ly(x=~b, y=~a, type="bar", orientation="h") %>%
add_trace(x=~b1, type="bar")
running above command we have
a <- dat %>% plot_ly(x=~c, y=~a, type="bar", orientation="h") %>%
add_trace(x=~c1, type="bar")
subplot(a, b)
a <- dat %>% plot_ly(x=~c, y=~a, type="bar", orientation="h") %>%
add_trace(x=~c1, type="bar") %>%
layout(xaxis=list(range=c(15,0))
so the plot is reversed now.
stacked bar mode example

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store