0
df <- data.frame(value = c(1, 2, 1.5), bin = c('B', 'C', 'D'))
p <- ggplot(data = df, aes(x = df$bin, y = df$value, group = 1)) + geom_line() + geom_point()

I want an x tick for 'A' that has no value or line it it. I have other plots that do have a value for 'A' and I want to make all axes consistent.

I was hoping this would work, but it does not:

p + scale_x_discrete(breaks = c('A', 'B', 'C', 'D'))

enter image description here

1 Answer 1

1

use this instead:

p + scale_x_discrete(limits = c('A', 'B', 'C', 'D'))

enter image description here


Also, it's better if you don't use df$ inside aes.

Better this way:

p <- ggplot(data = df, aes(x = bin, y = value, group = 1)) +
  geom_line() + 
  geom_point()
Sign up to request clarification or add additional context in comments.

Comments

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.