使用ggplot2时持续无效的图形状态错误 [英] Persistent invalid graphics state error when using ggplot2

查看:722
本文介绍了使用ggplot2时持续无效的图形状态错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我的数据框没问题,我的代码也没问题。事实上,我已经消除了部分数据框和大部分图形代码,以尽可能地使事情变得基本。但是,我仍然得到:.call.graphics(C_palette2,.Call(C_palette2,NULL))中的错误:

  $ b无效图形状态

这里有什么问题?以下是数据:

  date trt var val 
1/8/2008 cc sw5 0.2684138
1 / 8/2008 cc sw15 0.2897586
1/8/2008 cc sw5 0.2822414
2/8/2008 cc sw5 0.2494583
2/8/2008 cc sw5 0.2692917
2/8 / 2008 cc sw15 0.2619167
2/8/2008 cc sw5 0.204375
3/8/2008 cc sw5 0.2430625
3/8/2008 cc sw5 0.2654375
3/8/2008 cc sw5 0.2509583
3/8/2008 cc sw5 0.2055625
1/8/2008 ccw sw15 0.2212414
1/8/2008 ccw sw5 0.3613448
1/8/2008 ccw sw5 0.2607586
2/8/2008 ccw sw5 0.2087917
2/8/2008 ccw sw15 0.3390417
2/8/2008 ccw sw5 0.2436458
2/8/2008 ccw sw5 0.290875
3/8/2008 ccw sw5 0.20175
3/8/2008 ccw sw15 0.328875
3/8/2008 ccw sw5 0.2328958
3/8/2008 ccw sw5 0.2868958

当我处理这些数据时,我会指定如下的日期:

  df <-df [order(as.Date(df $ date,f ormat =%d /%m /%Y)),, drop = FALSE] 

和这里我想做一个scatterplot:

pre $ g $ pggplot(data = df,aes(x = date,y = val))+
geom_point(aes(group = trt))


解决方案

<

  dev.off()
我遇到了同样的错误并通过运行解决了它: c $ c>

,然后再次运行该图。我认为这个图形设备早就以某种方式搞乱了,通过导出一些图形并且它没有得到重置。这对我很有用,比重新安装ggp​​lot2更简单。


I believe my dataframe is okay and my code is okay. In fact, I have eliminated parts of the dataframe and most of the graphing code to make things as basic as possible. But still, I get:

Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) : 
  invalid graphics state

What is wrong here? Here is the data:

 date   trt var val
1/8/2008    cc  sw5 0.2684138
1/8/2008    cc  sw15    0.2897586
1/8/2008    cc  sw5 0.2822414
2/8/2008    cc  sw5 0.2494583
2/8/2008    cc  sw5 0.2692917
2/8/2008    cc  sw15    0.2619167
2/8/2008    cc  sw5 0.204375
3/8/2008    cc  sw5 0.2430625
3/8/2008    cc  sw5 0.2654375
3/8/2008    cc  sw5 0.2509583
3/8/2008    cc  sw5 0.2055625
1/8/2008    ccw sw15    0.2212414
1/8/2008    ccw sw5 0.3613448
1/8/2008    ccw sw5 0.2607586
2/8/2008    ccw sw5 0.2087917
2/8/2008    ccw sw15    0.3390417
2/8/2008    ccw sw5 0.2436458
2/8/2008    ccw sw5 0.290875
3/8/2008    ccw sw5 0.20175
3/8/2008    ccw sw15    0.328875
3/8/2008    ccw sw5 0.2328958
3/8/2008    ccw sw5 0.2868958

When I work with this data, I specify dates like this:

df<-df[order(as.Date(df$date,format="%d/%m/%Y")),,drop=FALSE]

and here I want to make a scatterplot:

ggplot(data = df,aes(x = date,y = val)) + 
 geom_point(aes(group = trt))

解决方案

I ran into this same error and solved it by running:

dev.off()

and then running the plot again. I think the graphics device was messed up earlier somehow by exporting some graphics and it didn't get reset. This worked for me and it's simpler than reinstalling ggplot2.

这篇关于使用ggplot2时持续无效的图形状态错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆