Rfanatic
Rfanatic

Reputation: 2282

Turning data into horizontal bar graph with ggplot2

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:

enter image description here

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.

enter image description here

UPDATE@ How can I change the x axis of this graph?

Many tahnks

Upvotes: 1

Views: 91

Answers (1)

demarsylvain
demarsylvain

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

Related Questions