Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot未在中绘图_R_Ggplot2 - Fatal编程技术网

R ggplot未在中绘图

R ggplot未在中绘图,r,ggplot2,R,Ggplot2,我已经看了一段时间了,有人看到这个ggplot语法有什么错误吗?我得到这个错误: Error: Discrete value supplied to continuous scale 这是z: Month Value 1 2011-01-01 11 2 2011-02-01 5 3 2011-03-01 6 4 2011-04-01 6 5 2011-05-01 4 6 2011-06-01 5 7 2011-07-01

我已经看了一段时间了,有人看到这个ggplot语法有什么错误吗?我得到这个错误:

Error: Discrete value supplied to continuous scale
这是z:

     Month Value
1  2011-01-01    11
2  2011-02-01     5
3  2011-03-01     6
4  2011-04-01     6
5  2011-05-01     4
6  2011-06-01     5
7  2011-07-01     3
8  2011-08-01     9
9  2011-09-01    19
10 2011-10-01     3
11 2011-11-01     6
12 2011-12-01     2
13 2012-01-01     1
14 2012-02-01     4
15 2012-04-01     1
16 2012-05-01     2
17 2012-06-01    11
18 2012-07-01     5


ggplot(z, aes(Month, Value)) + 
  geom_bar(fill="orange",size=.3)  + 
  theme_bw() + scale_x_discrete(name="Date") +   
  scale_y_continuous("Number") +
  opts(title="Monthly issues", 
       axis.title.x = theme_text(face="bold", colour="#990000"), 
       axis.text.x  = theme_text(angle=90), 
       axis.title.y = theme_text(face="bold", colour="#990000", angle=90)
   ) + 
  geom_smooth(data=z,aes(Month,Value,group=1), method="lm", size=2, color="darkblue")

啊哈!问题是您的
Month
列,正如您在评论中所注意到的,该列存储为日期。R认为这是一个连续变量,因此存在
scale\u x\u discrete
的误差。如果要与
geom\u bar
一起使用,您可能应该将其转换为带有
as.character
的字符!问题是您的
Month
列,正如您在评论中所注意到的,该列存储为日期。R认为这是一个连续变量,因此存在
scale\u x\u discrete
的误差。您可能应该将其转换为带有
as.character
的字符,如果您想将其与
geom\u bar

一起使用,它对我来说运行良好,并且生成的绘图也很好。检查
str(z)
并确保没有将
值存储为因子。这是str(z):str(z)'data.frame':18 obs的输出。共2个变量:$Month:日期,格式:“2011-01-01”“2011-02-01”“2011-03-01”“2011-04-01”…$值:num 11 5 6 6 4 5 3 9 19 3…它对我来说运行良好,生成的绘图也很好。检查
str(z)
并确保没有将
值存储为因子。这是str(z):str(z)'data.frame':18 obs的输出。共2个变量:$Month:日期,格式:“2011-01-01”“2011-02-01”“2011-03-01”“2011-04-01”…$值:num 11 5 6 6 4 5 3 9 19 3…是的,当我做这个z时$Month@MikeDude这是一个完全不同的问题,非常普遍,非常感谢。这是一个很大的收获(如角色)。我终于能够通过grid.arrange绕过图像生成,不确定更好的方法,但是,这将为我做到这一点$Month@MikeDude这是一个完全不同的问题,非常普遍,非常感谢。这是一个很大的收获(如角色)。我终于能够通过grid.arrange绕过图像生成,不确定是否有更好的方法,但是,这将为我做到这一点。