I need to change the family and size of a specific x-axis element of a barplot, based on a condition.
I can successfully modify face using:
library(ggplot2)
ggplot(iris, aes(Species, Petal.Length)) +
geom_boxplot() +
coord_flip() +
theme(axis.text.y = element_text(face = ifelse(levels(iris$Species)=="setosa","bold","italic")))
As suggested by: https://stackoverflow.com/a/20609878/8534926
However, for some reason when I try to apply family and size an empty gap is created between the axis and names.
ggplot(iris, aes(Species, Petal.Length)) +
geom_boxplot() + coord_flip() +
theme(axis.text.y = element_text(family = ifelse(levels(iris$Species)=="setosa","sans","mono")))
or
ggplot(iris, aes(Species, Petal.Length)) +
geom_boxplot() + coord_flip() +
theme(axis.text.y = element_text(size = ifelse(levels(iris$Species)=="setosa", 10, 20)))
I try to edit it using margin, but overlays can occur when the names are modified (using shiny app, for example).
what is this gap? Can I delete it?