moomin_valley
moomin_valley

Reputation: 43

How to color part of a histogram different than another part, based on a cutoff value?

I am trying to visualize (a) the distribution of a variable, and also (b)the proportion of one value of that variable compared to others.

In the example below, I want to make a histogram of health scores 1-5, and leave the '1-3' and '5' portions colored grey but color the '4' portion a bright color.

How could I do this?

I am using the packages tidyverse, plyr, and skimr and working in RStudio with cdc data.

Thank you!

recode <- mapvalues(cdc$genhlth, from = c("excellent", "very good", "good", "fair", "poor"), to = c("5", "4", "3", "2", "1"))

ggplot(cdc, aes(recode) +
geom_histogram() +
  ggtitle("Distribution of General Health & Proportion of Very Good Health") 
# then go back in here later and color the 4's

Upvotes: 0

Views: 63

Answers (1)

A hackaround if this is case specific could be to add a second layer with geom_col(x=4,y=count at 4) with the same width as the geom_histogram

Upvotes: 1

Related Questions