繁体   English   中英

Geom_Bar 错误与“labels = scales::comma”

[英]Geom_Bar Error With "labels = scales::comma"

新的 R 用户在这里! 我想自定义 y 轴以显示带有自定义中断的逗号。

这是尝试添加逗号之前的样子:

ggplot(data = bike_data_v4, aes(x = member_casual, fill = rideable_type)) +
  geom_bar() +
  labs(title="Usage of Different Bike Types by Riders",
       x = "Rider Type", y = "Count") +
  scale_y_continuous(breaks = c(0,500000, 1000000, 1500000, 2000000, 2500000))

在此处输入图像描述

添加 scales::comma 时,我收到此错误:

ggplot(data = bike_data_v4, aes(x = member_casual, fill = rideable_type)) +
  geom_bar() +
  labs(title="Usage of Different Bike Types by Riders",
       x = "Rider Type", y = "Count") +
  scale_y_continuous(breaks = c(0,500000, 1000000, 1500000, 2000000, 2500000, labels = scales::comma))

Error in censor(breaks, self$trans$transform(limits), only.finite = FALSE) : 
  'list' object cannot be coerced to type 'double'

我读过这可能需要像 as.numeric(unlist(x)) 这样的东西。 y 轴似乎只是字符变量“rideable_type”的计数,所以我不确定如何操作它以使其工作。

paqmo 为我解决了这个问题!

“看起来你有一个放错位置的括号。在设置标签之前关闭中断值向量:scale_y_continuous(breaks = c(0,500000, 1000000, 1500000, 2000000, 2500000), labels = scales::comma)”

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM