Question

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

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

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

Was it helpful?

Solution

I think your problem is that you're calling legend() inside your call to boxplot() whereas it's supposed to be called after. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top