Challenge:I need to automatically (without hard coding) customize x axis text in my graph, as follows. This is exclusively for aesthetic appeal for my users:
- Two rows of text needed in place of x axis text. First row, displays a sub-category (Role) while the second row (breed) displays a main category. See reprex code data set below
- Vertical line separating the main categories
See attached plot where I had manually scribbled what I want to achieve.
Here is a reproducible example code.
require(tidyverse)
bark <- tribble(
~breed, ~value, ~role, ~id,
"Bulldog", 1, "Dad", "A",
"Bulldog", 1, "Mom", "B",
"Bulldog", 2, "Ch1", "C",
"Bulldog", 1, "Ch2", "D",
"Bulldog", 2, "Ch3", "E",
"Poodle", 1, "Dad", "F",
"Poodle", 3, "Mom", "G",
"Poodle", 1, "Ch1", "H",
"Poodle", 4, "Ch2", "I",
"Beagle", 1, "Mom", "J",
"Beagle", 5, "Ch1", "K",
"Beagle", 1, "Ch2", "L",
"Pug", 1, "Mom", "M",
"Pug", 2, "Dad", "N",
"Pug", 3, "Ch2", "O",
"Pug", 1, "Ch3", "P",
"Boxer", 5, "Dad", "Q",
"Boxer", 4, "Ch1", "R"
)
ggplot2::ggplot(data=bark,aes(x=id,y=value))+geom_point()+geom_text(aes(y=1,label=role))+theme(axis.title = element_blank(),axis.text.x = element_blank())
This is what I want to achieve