3

I am trying to make a graph in ggplot2. I want the x-axis to show 2.84 along with the sequence typed below. Is there any other way beside typing all the exact values in breaks()? I tried google but it doesn't solve my problem.

scale_x_continuous(limits = c(1, 7), seq(1,7,by=0.5), name = "Number of 
treatments")
Claus Wilke
  • 16,992
  • 7
  • 53
  • 104
cmirian
  • 2,572
  • 3
  • 19
  • 59
  • Welcome to Stackoverflow. Please always provide a [minimal, reproducible example.](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) Otherwise, we don't know exactly what it is you're trying to achieve, and you risk having your question closed as "unclear what you're asking". – Claus Wilke Dec 21 '17 at 18:45

1 Answers1

5

You can programmatically generate specific breaks, like this:

# make up some data
d <- data.frame(x = 6*runif(10) + 1,
                y = runif(10))

# generate break positions
breaks = c(seq(1, 7, by=0.5), 2.84)
# and labels
labels = as.character(breaks)

# plot
ggplot(d, aes(x, y)) + geom_point() + theme_minimal() +
  scale_x_continuous(limits = c(1, 7), breaks = breaks, labels = labels,
                     name = "Number of treatments")

enter image description here

Claus Wilke
  • 16,992
  • 7
  • 53
  • 104