【问题标题】:Missing values in geom_point()geom_point() 中的缺失值
【发布时间】:2021-03-09 21:14:20
【问题描述】:

所以我有一个情节需要我很长时间才能制作出来。它需要指定月份并且既是一条线又是这样的点:

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

警告消息: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))

数据如下所示:

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

任何帮助将不胜感激:)

【问题讨论】:

  • 你好斯蒂芬,欢迎光临!很难为您提供数据集的图像。请运行 dput(Rate_time) 为我们提供一个可重现的示例。

标签: r ggplot2 line geom-point


【解决方案1】:

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

set.seed(123)
#Works as is
Rate_time<- data.frame(Month=month.abb, Rate=runif(12, 0, 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))

【讨论】:

  • 是的,就是这样。九月至九月,它的工作原理。谢谢!只是为了展示编码的敏感程度!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 2019-10-22
相关资源
最近更新 更多