Adam_G
Adam_G

Reputation: 7879

Cannot customize ggplot x-axis tick labels

I am trying to coerce the ticks of the x-axis to be the individual characters in a character vector. How can this be accomplished?

I've tried:

char.list <- c('a','l','t','e','r','e','d')
times <- c(1:7)    
df <- as.data.frame(list('chars'=char.list, 'times'=times))
g <- ggplot(data=df, aes(x=1:length(char.list), y=times)) +
      scale_x_discrete("Characters",breaks=char.list, 
                       labels=char.list) + 
      geom_point(aes(size=10, colour='red'))

When I try @Heroka's code, this results in:

enter image description here

Upvotes: 0

Views: 414

Answers (1)

dww
dww

Reputation: 31452

ggplot(data=df, aes(x=1:length(char.list), y=times)) +
  geom_point(aes(size=10, colour='red'))+
  scale_x_continuous(breaks=1:length(char.list), labels=char.list)

produces

enter image description here

Upvotes: 3

Related Questions