Reputation: 883
Here are two reproducible minimal examples for my request.
x
variable is a factor variable, I find the function geom_area
does not work, works like a geom_segment
output.x
variable from factor into interger, the function geom_area
works but I find the axis.text.y
labels are not what I want.Anyone know fix it?
suppressMessages(library(tidyverse))
mtcars %>%
rownames_to_column('index1') %>%
mutate(index1 = index1 %>% as.factor) %>%
mutate(index2 = index1 %>% as.integer) -> df
df %>%
ggplot() +
geom_area(aes(x = index1, y = mpg), color = 'black', fill = 'black') +
coord_flip()
df %>%
ggplot() +
geom_area(aes(x = index2, y = mpg), color = 'black', fill = 'black') +
coord_flip()
Upvotes: 2
Views: 33
Reputation: 2399
Check this solution:
library(tidyverse)
library(wrapr)
df %.>%
ggplot(data = .) +
geom_area(aes(x = index2, y = mpg), color = 'black', fill = 'black') +
coord_flip() +
scale_x_continuous(
breaks = .$index2,
labels = .$index1
)
Upvotes: 1