Steveman30290
Steveman30290

Reputation: 561

Remove Tick Marks But Keep Axis Label ggplot2 R

Let's say I have the following data.frame:

    structure(list(x = c("item_1", "item_2", "item_3", "item_4"), 
        y = c("location_1", "location_2", "location_3", "location_4"
        )), class = "data.frame", row.names = c(NA, -4L))

########################
#       x          y
#1 item_1 location_1
#2 item_2 location_2
#3 item_3 location_3
#4 item_4 location_4

With the following plot:

data %>% ggplot(aes(x,y)) + geom_point()

enter image description here

Is there a way to keep all four labels on the y-axis, but only show tick marks for location_4 and location_1?

Upvotes: 0

Views: 1163

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 174586

Yes. The theme element axis.ticks.y will take vectorized colours.

data %>% 
  ggplot(aes(x,y)) + 
  geom_point() +
  theme(axis.ticks.y = element_line(color = c("black", NA, NA, "black")),
        axis.ticks.length = unit(5, "points"))

enter image description here

Upvotes: 2

Related Questions