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