Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...