AKMartin
AKMartin

Reputation: 29

Change tick labels on x-axis ggplot2

In ggplot2 I have created a line graph and have it looking how I want it. However, I am having difficulties changing the values on the x-axis. How can I change the x-axis tick labels from the numbers 1-10 to some text?

Here is my code:

pd <- position_dodge(0.1) 

myplot <- ggplot(LL_young_gg, aes(x=Day, y=Mean, colour=Group)) + 
      geom_errorbar(aes(ymin=Mean-SEM, ymax=Mean+SEM), width=.1, position=pd) +
      geom_line(position=pd) + scale_color_manual(values=c("red", "pink", "dark blue", " light blue")) +
      geom_point(position=pd)

myplot + theme_bw() +
  theme(axis.line = element_line(colour = "black"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank())

The database (LL_young_gg) is imported from excel and the column (Day) is numeric 1 through to 10.

Upvotes: 1

Views: 5838

Answers (1)

Graeme Frost
Graeme Frost

Reputation: 2643

you can use scale_x_continuous(). A reproducible example:

library(ggplot2)

data(mtcars)

xLabels <- paste(c(4,6,8), "Cylinders")

ggplot(mtcars,
       aes(x = cyl,
           y = qsec
           )
       ) +
  geom_point() +
  scale_x_continuous(breaks = c(4,6,8),
                     labels = xLabels
                     )

enter image description here

Upvotes: 2

Related Questions