ggplot2: using one column in pie chart and calculate the number of appearances

18 Views Asked by At

I have one column in my dataset called day_of_week, as the name suggests this column represents what day of the week it is with values from 1 to 7, 1 = Sunday.

I'm trying to use this column in a pie chart to see how much each day represents from the total. I don't want to add another column to my dataset for this, it will be useless, I want to find a function that could do this for me and how I can use it in a pie chart.

Note: the dataset has over 5 million rows.

I've tried the count function to calculate the number of appearances for each value, it worked outside the aes function but didn't work inside it.

I'm new to R and trying to get my head around things.

Here is the head of my dataset:

ride_id rideable_type started_at          ended_at            ride_length day_of_week 
  <chr>   <chr>         <dttm>              <dttm>              <time>            <dbl>
1 000000… electric_bike 2023-09-24 12:56:50 2023-09-24 13:00:43 03'53"                1 
2 000008… electric_bike 2023-04-13 17:52:05 2023-04-13 18:10:33 18'28"                5 
3 000008… docked_bike   2023-05-08 13:22:50 2023-05-08 13:28:53 06'03"                2 
4 00000B… electric_bike 2023-12-08 17:52:37 2023-12-08 18:00:54 08'17"                6 
5 000010… electric_bike 2023-11-10 17:46:50 2023-11-10 17:59:41 12'51"                6 
6 000014… classic_bike  2023-06-21 20:19:43 2023-06-21 20:32:04 12'21"                4 
0

There are 0 best solutions below