简体   繁体   中英

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:

在此处输入图片说明

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM