Reputation: 2282
I would like to create a horizontal bar graph from my data.
The link to my data is here.
The code that I am using
library(ggplot2)
ggplot(data=df , aes(x=fct_inorder(WorkSchedule),y=timing, fill=Value)) + geom_col() + coord_flip()
The output of the plot:
How to change the x-axis
to show time from 04:00 till 03:45 (24h)
I tried factor(Source)
but it does not work.
UPDATE@ How can I change the x axis of this graph?
Many tahnks
Upvotes: 1
Views: 91
Reputation: 2185
With the function lvls_reorder()
from library forçats, you can specify the order of the levels of your variable.
library(tidyverse) # forcats is included in tidyverse library
df <- df %>%
mutate(Workschedule = lvls_reorder(Workschedule, c(3,2,4,5,1))
If you transform the variable Source
as a factor, you can also determine the order you want.
Upvotes: 1