Interesting error. Somehow it doesn't like the numbers on the x-axis and for the fill.
It works well with A,B,C.
You can convert the numbers to characters, or add an "as.factor" to the fill line.
#this isn't working:
sleepDay_merged = tibble(
"total_sleep_records" = c(rep(1, 300),
rep(2, 100),
rep(3, 10)) )
ggplot(sleepDay_merged,
aes(total_sleep_records, fill = total_sleep_records)) +
geom_bar()
# this works fine:
sleepDay_merged = tibble(
"total_sleep_records" = c(rep("A", 300),
rep("B", 100),
rep("C", 10)) )
ggplot(sleepDay_merged,
aes(total_sleep_records, fill = total_sleep_records)) +
geom_bar()
#it works with a factor:
sleepDay_merged = tibble(
"total_sleep_records" = c(rep(1, 300),
rep(2, 100),
rep(3, 10)) )
ggplot(sleepDay_merged,
aes(x = total_sleep_records,
fill = as.factor(total_sleep_records))) +
geom_bar()
#or when treating the number as character:
sleepDay_merged = tibble(
"total_sleep_records" = c(rep("1", 300),
rep("2", 100),
rep("3", 10)) )
ggplot(sleepDay_merged,
aes(total_sleep_records, fill = total_sleep_records)) +
geom_bar()