Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting axis intervals in ggplot

I have searched for this and can't believe I can't find it. Perhaps I've been asking the wrong question.

I have a set of data laid out in a histogram that has a xlim of $2,000,000. I am trying to set an interval of $100,000 for the breaks (rather than manually listing out every break with break = c(0, 50000, 100000, etc). How can I do this in ggplot? The breaks (ticks) are more important than the labels as I'll likely edit in Illustrator an abbreviated label (100k, etc)

p <- ggplot(mcsim, aes(result))
+ scale_x_continuous(formatter = "dollar") 
+ geom_histogram(aes(y = (..count..)/sum(..count..))) + scale_y_continuous(formatter = 'percent')

Thanks!

enter image description here

like image 998
A.Krueger Avatar asked Sep 26 '11 23:09

A.Krueger


People also ask

How do I change the axis interval in R?

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How do I change axis numbers in ggplot2?

Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.

How do I change Xticks in R?

Option 1. Set xaxt = "n" and yaxt = "n" to remove the tick labels of the plot and add the new labels with the axis function. Note that the at argument sets where to show the tick marks.


1 Answers

You can use breaks=seq(0, 2000000, by=100000). Effectively you are using seq to generate that vector you don't want to type out by hand.

like image 174
Brian Diggs Avatar answered Sep 26 '22 05:09

Brian Diggs