微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

geom_point() 中的缺失值

如何解决geom_point() 中的缺失值

所以我有一个花了我很长时间才制作出来的情节。它需要指定月份并且既是线又是点,如下所示:

enter image description here

但是我收到此错误消息并且“九月”没有显示一个点。

警告消息:1:删除了 1 行包含缺失值 (geom_path)。 2: 删除了 1 行包含缺失值 (geom_point)。

这是我的情节的代码

ggplot(Rate_time,aes (x=Month,y = Rate)) + 
  geom_line(aes(group=1),colour = "Orange") + 
  geom_point(colour = "Orange") + 
  theme_classic() + 
  scale_x_discrete(limits = month.abb) + 
  labs (y = "Rate (%)",x = "Month (2019)") + 
  theme(axis.text.x = element_text(colour = "black")) + 
  theme(axis.text.y = element_text(colour = "black")) + 
  theme(text=element_text(size=11,family="serif")) + 
  scale_y_continuous(limits=c(0,0.25))

数据如下:

enter image description here

我目前没有代码格式的数据,但可以在需要时执行此操作。我试过扩大 y 轴,但没有运气。我不确定如何处理这个错误,同时将月份保留为单词而不是数字。

任何帮助将不胜感激:)

解决方法

R 没有将“九月”识别为九月。尝试改用“Sep”。

set.seed(123)
#Works as is
Rate_time<- data.frame(Month=month.abb,Rate=runif(12,0.25))


#add this line to reproduce your problem.
#changes Sep to Sept
#Rate_time$Month[9] <- "Sept"

ggplot(Rate_time,aes (x=Month,y = Rate)) + 
   geom_line(aes(group=1),colour = "Orange") + 
   geom_point(colour = "Orange") + 
   theme_classic() + 
   scale_x_discrete(limits = month.abb) + 
   labs (y = "Rate (%)",x = "Month (2019)") + 
   theme(axis.text.x = element_text(colour = "black")) + 
   theme(axis.text.y = element_text(colour = "black")) + 
   theme(text=element_text(size=11,family="serif")) + 
   scale_y_continuous(limits=c(0,0.25))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。