The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Data Visuazlization Course: Histogram Homework (Age Distribution of Survey Participants) –> Python and R

Data Visuazlization Course: Histogram Homework (Age Distribution of Survey Participants) –> Python and R

Super Learner
0
Votes
1
Answer

Hello,
Can someone please advise on how to add the the bin interval labels to show on the x-axis in both Python and R :
 
-> I.e instead of X axis labels shown as 20 — 40  — 60 — 80 –> How can we edit it to show something along the lines in Excel or Tableau as follows:
[18,24] (24,30] (30-36] ….up to (72, 78]
 
My attempt at a solution in R was adding a Labels variable with the bin intervals as strings:

agelabels <- c("[0, 24]","(24, 30]","(30, 36]","(36, 42]","(42, 48]","(48, 54]","(54, 60]",               "35-39","40-44","45-49","50-54","55-59","60-64","65-69",
"(60, 66]","(66, 72]","(72+ ]")

But I cant figure out where in ggplot to display the labels (something like aes(label = agelabels)) ?!
 
Best regards,
 
Matt

1 Answer

365 Team
0
Votes

Hi Matt, 
thanks for reaching out!
For R studio what if you tried something along these lines:
 
real_estate$interval <- cut(real_estate$Price, seq (0, 550, by = 50)) // this essentially splits the original variable into intervals, which you then plot with a histogram
new_hist <- ggplot (real_estate, aes(interval)) +
geom_histogram(stat = “count”)
 
Best, 
365 Eli