简体   繁体   English

R:绘图,结果为“ plot.new尚未被调用”

[英]R: plot & the result is “plot.new has not been called yet”

Data (an abridged version): 数据(节略版):

m1 1
m2 2
m3 3
m4 0
m5 32
m6 12
m7 42
m8 56
m9 29

Note: 0 is supposed to represent a space in my graph 注意:0应该代表我的图表中的空间

Code: 码:

barplot(
  name,
  main="Mike vs. Ike" , 
  ylab="Number of criminal offences of two different people" , 
  xlab="" , 
  col=c("yellow" , "blue" ) , 
  beside=TRUE , 
  ylim= range(0 , 10) ,  
  las=2 , 
  axes=TRUE ,


   names.arg = c("Mike: number of offences in: 1 day"      , 
                    "Ike: number of offences in: 1 day"     ,
                    ""                       , 
                    "Mike: number of offences in: 1 week"      ,
                    "Ike: number of offences in: 1 week"     , 
                        ""                       ,
                        "Mike: number of offences in: 1 month"        ,
                        "Ike: number of offences in: 1 month"       , 
                        ""                       ,
                        "Mike: number of offences in: 1 year"     ,
                        "Mike: number of offences in: 1 year"   


           ) ,
             legend(
  "topright" , 
  c("Mike" , "Ike") , 
  col=c("yellow" , "green") , 
  pch=c(22:22) ,
  cex=0.75 )
)  

Error I get: 错误我得到:

Error in strwidth(legend, units = "user", cex = cex, font = text.font) : 
  plot.new has not been called yet

Billion $ question: 十亿美元的问题:

How can I scale my names.arg and legend to fit my graph 如何缩放我的names.arglegend以适合我的图表

Danke in advance 提前丹科

Don't read pass here (stack says too much code). 不要在这里读通行证(堆栈说太多代码)。

apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange apple orange 苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子苹果桔子

I think your problem is that you're calling legend() inside your call to boxplot() whereas it's supposed to be called after . 我觉得你的问题是,我们在调用legend()的调用内部 boxplot()而它应该被称为 At least that's what's giving you the error. 至少那是给您错误的原因。 I'm not sure exactly what you mean by "scaling" the legend or names however. 但是,我不确定“缩放”图例或名称​​的确切含义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM