Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2 bar chart convert label from seconds to min:sec

I want to create a bar-chart where the y-axis uses "min:sec" as labels. However, the data I want to display has seconds as units. What is now the best approach to do this?

zone  time_in_zone
   1           305
   2           664
   3          1945
   4          1187

I would plot this data using:

ggplot(data, aes(fill=zone, y=time_in_zone, x=zone))+
  geom_bar(stat="identity")

enter image description here

However, I fail converting the y-axis to a meaningful time series.

like image 800
user2912328 Avatar asked Oct 15 '25 17:10

user2912328


1 Answers

You can add scale_y_time to your plot like this...

ggplot(data, aes(fill=zone, y=time_in_zone, x=zone))+
    geom_bar(stat="identity") +
    scale_y_time()

Which should give you a time formatted y axis like this...

plot with time y-axis


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!