How can facet_grid () be configured so that the y-axis only displays the topmost value in each case, and nothing in between?

I have a facet_grid function that shows the survival rates of people aboard the Titanic based on their names.

enter image description here

Each line shows a range of titles (eg, "Mr.", "Doctor", etc.).

I set it scales="free"

internally facet_grid()

so that each y-axis is tailored for the group it identifies.

However, since there are many groups / titles, I want the y-axis in each edge grid to only display the topmost value, not everything in between. For example, if 40 people who were known as "Mr." were killed, then I want the top of the y-axis to be "Mr.", the grid has a face to show a value of 40, and nothing else below that. However, if only one person has died, I do not want the y-axis to read: 0.00, 0.25, 0.50, 1.00

as these values ​​"in between" have no meaning.

Can this be achieved?

+3


source to share


1 answer


try it

custom_breaks <- function(x) range(x)

ggplot(mpg, aes(displ, cty)) + geom_point() +
  facet_grid( cyl~., scales="free") +
  scale_y_continuous(breaks = custom_breaks)

      



enter image description here

+5


source







All Articles