Search code examples
rggplot2geom

How do I show only the y axis and hide everything else - including the plot itself and the x axis?


I need to show only the elements of the y axis and nothing else.

name <- c("A", "B", "C", "D", "E")
values <- c(1, 2, 3, 4, 5)
data<-data.frame(name, values)

ggplot()
geom_blank(data=data, aes(y=reorder(name,desc(name))))+
theme(axis.text.x=element_blank(),
axis.title = element_blank(), 
axis.text.y=element_text(colour="black"))

This still shows the plot. I want to show only the y axis elements.


Solution

  • If your aim is just to draw five letters without anything else, no need to bother with axes, but draw the labels directly.

    ggplot() + 
      annotate(geom = "text", x = 1, y = 1:5, label = rev(LETTERS[1:5])) +
      theme_void()