Reputation: 2443
iris %>%
mutate(Species=as.integer(Species)) %>%
ggplot(aes(x = Sepal.Length, y = Species, group = Species)) +
geom_density_ridges()
Above script works well and output as below:
But when I add breaks to y axis, the breaks disappear.
iris %>%
mutate(Species=as.integer(Species)) %>%
ggplot(aes(x = Sepal.Length, y = Species, group = Species)) +
scale_y_discrete(limit=c(0,30),breaks = seq(0,30,1))+
geom_density_ridges()
Where is the problem?
Upvotes: 0
Views: 322
Reputation:
If you have a (continuous) numeric y axis, you need to use scale_y_continuous()
(which takes number breaks) rather than scale_y_discrete()
(which takes a character vector of breaks). I'll use your example, however, it doesn't make much sense to me as you're converting Species
to integers...:
# working nonsense
iris %>%
mutate(Species=as.integer(Species)) %>%
ggplot(aes(x = Sepal.Length, y = Species, group = Species)) +
scale_y_continuous(limit=c(0,30),breaks = seq(0,30,1))+
geom_density_ridges()
This works as you probably want (integer breaks are displayed), but, as I say, it seems to be a nonsense.
geom_density_ridges()
is used rather for displaying multiple density plots with categorical data on y axis, like this:
iris %>%
ggplot(aes(x = Sepal.Length, y = Species)) +
geom_density_ridges()
Upvotes: 1