0

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Allan, you are the best! I didn't even think about altering the color. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.