0

In ggplot2, I set breaks for a histogram, and the tick labels automatically shows all the breaks, is there a way to customize the showing tick labels?

ggplot(plotdata,aes(x=vals))+
geom_histogram(aes(y=..density..),fill='cyan')+
geom_vline(aes(xintercept=mycrit,color='red'))+
scale_x_continuous(name='',breaks=mybreaks)+
theme(axis.text.x=element_text(angle=90))

enter image description here I don't want that many tick labels, only a fraction of them, is there a way to do that?

I also tried setting binwidth instead of breaks and set labels, but I got the error messageBreaks and Labels are different lengths

aosmith
  • 34,856
  • 9
  • 84
  • 118
Nancy Zhu
  • 40
  • 7
  • Is your x-axis supposed to be continuous or is it supposed to be categorical? I think you just need to convert it to `numeric`, that is `plotdata$vals = as.numeric(as.character(plotdata$vals))`. Suggested duplicate: [R-FAQ on How to convert from factor to numeric](https://stackoverflow.com/q/3418128/903061) – Gregor Thomas Aug 02 '17 at 23:12
  • the vals variable was already a `numeric` variable. I figured out my problem the other way. Thanks! – Nancy Zhu Aug 03 '17 at 13:11

1 Answers1

-1
plotdata$vals <- as.numeric(plotdata$vals)

Then run your code.

Brian
  • 7,900
  • 1
  • 27
  • 41