r语言 - ggplot() 有错误:缺少需要 TRUE/FALSE 的值



我正在尝试使用ggplot() .百分比的数据类型为双精度。在数据集中,"百分比"和"年份"列中都没有 NA。

l1 <- ggplot(data, aes(Year, Percentage)) + 
  scale_x_discrete(name="Year From 2015 to 2018") + 
  scale_y_discrete(name="Employment Outcomes")

错误说:

Error in if (zero_range(from) || zero_range(to)) { : 
  missing value where TRUE/FALSE needed

在您的情况下,您需要指定要生成的可视化类型。例如,如果要可视化时间序列图,脚本将如下所示。

ggplot(data, aes(Year, Percentage)) + 
  geom_line() +
  scale_x_discrete(name="Year From 2015 to 2018") + 
  scale_y_discrete(name="Employment Outcomes")

基本上,您需要在ggplot()之后指定geom_*()。另外,我的另一个建议是,使用 labs() not scale_x_discrete() 在 X/Y 轴上添加名称。

ggplot(data, aes(Year, Percentage)) + 
  geom_line() +
  labs(x = "Year From 2015 to 2018",
       y = "Employment Outcomes")

这将生成您想要的类似图。

最新更新