2

I have the following dataset (edited for readability):

chol <- read.table(url("http://assets.datacamp.com/blog_assets/chol.txt"), header = TRUE)

And I am creating a histogram of the data doing:

ggplot(data=chol, aes(chol$AGE)) + geom_histogram()

For a particular example I would like to change the x-labels however.

Any thoughts on how I can pull this of?

3
  • It might be helpful to have another hint on what is to be changed. I think you only want to apply a mapping from the (in this case with bins = 30) resulting 20, 30, 40, 50 and 60. But it would be better to know ;-) Commented Jun 2, 2016 at 10:27
  • 2
    use aes(AGE) rather than aes(chol$AGE). Use labs(x = "whatever") to set the x-axis label Commented Jun 2, 2016 at 10:29
  • My understanding was to not change the x-axis title but the labels on the tics of the x axis ... what is the right understanding? Commented Jun 2, 2016 at 10:40

1 Answer 1

0

To illustrate the answer (and better understand the question) a picture:

> require(ggplot2)
> chol <- read.table(url("http://assets.datacamp.com/blog_assets/chol.txt"), header = TRUE)
> ggplot(data=chol, aes(chol$AGE)) + geom_histogram()

yields:

The plot

There is the documentation (as we have a continuous not a discrete axis) at http://docs.ggplot2.org/current/scale_continuous.html

For a discrete axis one might have simply written:

> p <- ggplot(data=chol, aes(chol$AGE)) + geom_histogram() + scale_x_discrete(labels=c("20" = "twe", "30" = "thi", "40" = "fou", "50" = "fif", "60" = "six"))  # does NOT work cf. surrounding text.

A continuous axis at least allows formatting (cf. link for details).

Sign up to request clarification or add additional context in comments.

1 Comment

this is not really the solution to the question. There has to be some kind of a workaround... pls improve answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.