You have a discrete value on the x axis, so this is technically a bar chart rather than a histogram. You can use either geom_bar()
or geom_col()
for this:
medical %>%
group_by(numHospStays) %>%
summarise(val = sum(numVisits))
ggplot(aes(x = numHospStays, y = val)) +
geom_col(fill = "deepskyblue2", color = "black") +
labs(x = "Number of hospital stays", y = "Count")

or, to emphasize the exponential fall off in number of admissions, try a log scale on the y axis, plus perhaps a fill scale for aesthetic value and a tweak to the overall look using theme_bw
:
medical %>%
group_by(numHospStays) %>%
summarise(val = sum(numVisits))
ggplot(aes(x = numHospStays, y = val)) +
geom_col(aes(fill = numHospStays)) +
scale_fill_gradient(low = "forestgreen", high = "red", guide = guide_none()) +
labs(x = "Number of hospital stays", y = "Count") +
scale_y_log10() +
theme_bw()
