r - Set breaks of axis by level of factor in ggplot2 -


given plot x axis discrete, given ordered factor, plot:

enter image description here

with levels:

d e f g h j 1 1 1 2 2 3 4 

is there way do:

scale_x_discrete(breaks=c("d","g", "i", "j"), lables=c(1,2,3,4)) 

without manually copying breaks?

is you're after?

keeps<-c(1,4,6,7) # indices levels want show ggplot(data=diamonds)+   geom_bar(aes(x=color,y=carat),stat="identity")+   scale_x_discrete(     breaks=levels(d$color)[keeps],     labels=table(d$color)[keeps]) 

Comments