ggplot()有错误:缺少值需要TRUE / FALSE

问题描述 投票:0回答:1

我正在尝试使用ggplot()。百分比的数据类型为Double。在数据集中,“百分比”和“年”列中都没有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
r ggplot2
1个回答
0
投票

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

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

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

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

这会生成您想要的类似情节。

© www.soinside.com 2019 - 2024. All rights reserved.