Graph displaying 0e+00 on Y axis and cannot figure out why

Greetings,
I am having trouble identifying where my issue is with my code. When I create a graph, the y axis displays the correct label, however the increments are showing as really small numbers, 0e+00 through 4e+05. Yet, when I run the same code without the ggplot2 graph, the results appear correct, as in numbers greater than 0. I apologize, I tried to create a reprex but my RStudio got stuck in a restart cycle. I hope the text will suffice.

The y axis should (or at least I want it to) display the number_of_rides data, with
results 138280, 76785 and so on.

Yet, notice when graphed, the y axis displays the correct label but I have no idea
what numbers are being displayed.

This is the code chunk

total_trips %>%
mutate(weekday=wday(start_date,label=TRUE)) %>%
group_by(user_type,weekday) %>%
summarise(number_of_rides=n()
,average_duration=mean(length_of_ride)) %>%
arrange(user_type,weekday)

This is the result
(bolded values are what I was expected to be on the Y axis. dashes added for clarity).

user_type weekday number_of_rides average_duration
<chr <ord <int <dbl
1 casual - Sun - 138280 - 2378.
2 casual - Mon - 76785 - 2245.
3 casual - Tue - 71460 - 2151.
4 casual - Wed - 72259 - 2119.
5 casual - Thu - 80015 - 2165.
6 casual - Fri - 96079 - 2201.
7 casual - Sat - 158229 - 2390.
8 member - Sun - 217103 - 841.
9 member - Mon - 387643 - 736.
10 member - Tue - 422730 - 738.
11 member - Wed - 416505 - 740.
12 member - Thu - 404354 - 740.
13 member - Fri - 380518 - 735.
14 member - Sat - 232350 - 842.

This is the code chunk with ggplot

total_trips %>%
mutate(weekday=wday(start_date,label=TRUE)) %>%
group_by(user_type,weekday) %>%
summarise(number_of_rides=n()
,average_duration=mean(length_of_ride)) %>%
arrange(user_type,weekday) %>%
ggplot(aes(x=weekday,y=number_of_rides,fill=user_type)) +
geom_col(position = "dodge")

This is the resulting graph

I appreciate anyone's time and help, thank you.

Add this code:

... +
scale_y_continuous(labels = label_number(suffix = " k", scale = 1e-6))

It is somewhat confusing, but the scale is from 0 to over 400,000

0e+00 is 0 x 10^0 = 0
4e+05 is 4 x 10^5 = 400,000

Hi FLM,

Thank you for the suggestion. Unfortunately it did not work.

summarise() has grouped output by 'user_type'. You can override using the
.groups argument.
Error in label_number(suffix = "k", scale = 1e-06) :
could not find function "label_number"

Thank you

You should load "scales" library
scale_y_continuous(labels = scales::label_number(suffix = " k", scale = 1e-6))

ok, I will give that a go. I also updated my OP. It was sequestered by admin for a few days and I didn't realize my edits did not take. Sorry if I was not clear before and thank you again for taking the time to help a stranger.

I found a solution!

  • scale_y_continuous(name="this is the name of the Y axis", labels = scales::comma)
    (no need to install packages beyond ggplot2)

Thank you again for anyone who tried to help, much appreciated!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.