0

I'm having issues getting my plot in R to display the days of week. Whenever I attempt to plot the data, it just comes up as one big blob but it doesn't differentiate in the days of the week. I believe its caused by the ordered data type it is in however it doesn't have an order to the data. How would I go about putting the data in an order so I can display any days of the week?

enter image description here - what the graph looks like for me.

The code I'm using for the graph

ggplot(data = daily_activity_cleaned) + aes(x = day_of_week, y = total_steps) + 
    geom_col(fill = 'blue') + 
    labs(x = 'Day of week', y = 'Total Steps', title = 'Total steps taken in a week')

What data type it is

str(daily_activity_cleaned$day_of_week)
 Ord.factor w/ 7 levels "Sun"<"Mon"<"Tue"<..: NA NA NA NA NA NA NA NA NA NA ...

One of many options that I have tried to fix this problem.

daily_activity_cleaned$day_of_week <- wday(x, week_start ="lubridate.week.start", 7)

Thanks for all the help again and please let me know if I need to include anything else

Dave2e
  • 22,192
  • 18
  • 42
  • 50
rayban0622
  • 11
  • 1
  • 2
    It looks like your column is filled with "NA". The problem is caused prior to your code above. Can you provide a sample of the original data with `dput(head(daily_activity_cleaned))` and maybe the raw data also? – Dave2e Dec 28 '22 at 18:02
  • dput(head(daily_activity_cleaned$day_of_week)) structure(c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_), levels = c("Sun", "Mon", "Tue", "Wed", – rayban0622 Dec 29 '22 at 00:32
  • https://drive.google.com/file/d/1p_YQSPw4g5ZDZvCc4NBRHLh1ujJVzzKx/view?usp=share_link – rayban0622 Dec 29 '22 at 01:05
  • Thank you for your help Dave2e! Sorry for the late upload on the google drive link, I'm just a beginner and have a long way to go! – rayban0622 Dec 29 '22 at 01:06
  • 1
    The GoogleDrive link you posted does not match your code; your linked dataset doesn't contain the variables `day_of_week` or `total_steps`. Can you provide any relevant data [using `dput()` instead of external links](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – jrcalabrese Dec 29 '22 at 18:42

0 Answers0