0

I don't know how to make the quantities look as they should. As it should appear on saturday for casual (this is its amount: 437094) can anybody help me?

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

quantities look bad

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • 1
    Your question is missing two important components: sample data, and working code. Your code starts with `mutate(weekday=...)` which suggests that this is actually not the first line in your real code. If you ran the code that you gave us, you'd likely see `object 'started_at' not found`. – r2evans Jul 23 '22 at 23:40
  • 2
    `look as they should` is completely subjective. Are you talking about the y-axis numbers? Try adding `scale_y_continuous(labels=scales::comma)` or `scale_x_continuous(labels=scales::number)` – r2evans Jul 23 '22 at 23:47
  • Talking about the y-axis numbers. I mean they are quantities, for example, 50000 and it appeared like 5e+05 – MALCOLM MALINKE RUIZ HURTADO Jul 24 '22 at 00:42
  • Run `options(scipen = 99)` in the console and try to plot again. – Ronak Shah Jul 24 '22 at 00:45
  • Ronak Shan, thanks a bunch. It was helpful. Even though, the change disappears seconds later… – MALCOLM MALINKE RUIZ HURTADO Jul 24 '22 at 03:32
  • Did you try my recommendations? – r2evans Jul 24 '22 at 12:53

1 Answers1

-1

Just rescale prior to ggplot if you want:

Example Data

library(ggplot2)

set.seed(123)
N <- 50

df <- data.frame(x = 1:N,
           group = sample(c("casual", "member"), N, replace = TRUE),
           y = sample(100000:10000000, N, replace = TRUE)
)

Reproduces issue of y-axis in scientific notation

ggplot(df, aes(x = x, y = y, fill = group)) +
  geom_bar(stat = "identity") +
  ylab("Y")

Solution: rescale before passing to ggplot()

df$y_rescaled <- df$y / 1000000

ggplot(df, aes(x = x, y = y_rescaled, fill = group)) +
  geom_bar(stat = "identity") +
  ylab("Y (Millions)")

socialscientist
  • 3,759
  • 5
  • 23
  • 58