0

So, I tried to follow the advice from the Get a histogram plot of factor frequencies (summary) post, but I think that the problem is that I'm trying to define my factors using a row containing strings (instead of, say, generating one using rep()). I don't know whether that's okay to do, but clearly I'm doing something wrong. Any idea what's happening? Many thanks!

My data:

data<-structure(list(V1 = structure(c(2L, 1L), .Label = c("593", "QnWeight_initial"
), class = "factor"), V2 = structure(c(2L, 1L), .Label = c("482", 
"Left_Leg"), class = "factor"), V3 = structure(c(2L, 1L), .Label = c("474", 
"Left_Antenna"), class = "factor"), V4 = structure(c(2L, 1L), .Label = c("566", 
"Head"), class = "factor"), V5 = structure(c(2L, 1L), .Label = c("51", 
"Right_Antenna"), class = "factor"), V6 = structure(c(2L, 1L), .Label = c("49", 
"Right_Leg"), class = "factor"), V7 = structure(c(2L, 1L), .Label = c("49", 
"Left_Leg_Remeasure"), class = "factor"), V8 = structure(c(2L, 
1L), .Label = c("46", "Left_Antenna_Remeasure"), class = "factor"), 
    V9 = structure(c(2L, 1L), .Label = c("47", "Head_Remeasure"
    ), class = "factor"), V10 = structure(c(2L, 1L), .Label = c("230", 
    "Days_wrkr_eclosion"), class = "factor"), V11 = structure(c(2L, 
    1L), .Label = c("237", "Qn_Weight_Loss"), class = "factor"), 
    V12 = structure(c(2L, 1L), .Label = c("81", "Growth_all"), class = "factor"), 
    V13 = structure(c(2L, 1L), .Label = c("79", "Growth_1_2"), class = "factor"), 
    V14 = structure(c(2L, 1L), .Label = c("62", "Growth_1_3"), class = "factor"), 
    V15 = structure(c(2L, 1L), .Label = c("60", "Growth_2_3"), class = "factor"), 
    V16 = structure(c(2L, 1L), .Label = c("535", "V1"), class = "factor"), 
    V17 = structure(c(2L, 1L), .Label = c("535", "V2"), class = "factor"), 
    V18 = structure(c(2L, 1L), .Label = c("535", "V3"), class = "factor")), .Names = c("V1", 
"V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", 
"V12", "V13", "V14", "V15", "V16", "V17", "V18"), class = "data.frame", row.names = c(NA, 
-2L))

My code:

dat<-data.frame(fac=data[1,], freqs=data[2,])

print(dat)
str(dat)
barplot(dat, main="Sample Sizes of Various Fitness Traits")
Community
  • 1
  • 1
Atticus29
  • 4,190
  • 18
  • 47
  • 84

1 Answers1

0

I'm not sure if this is what you're after and there's likely a better way (I use ggplot2 so am not terribly familiar with base). Here's an approach but you have to use rep and table:

dat<-data.frame(fac=unlist(data[1,, drop=FALSE]), freqs=unlist(data[2,, drop=FALSE]))
barplot(table(rep(as.character(dat[, 1]), dat[, 2])), 
    main="Sample Sizes of Various Fitness Traits")
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
  • It is, except the frequencies actually being plotted in this case are not the numbers in the second column, which is kind of what I was hoping for. – Atticus29 Sep 18 '12 at 02:42
  • I asked a very similar question just now here: http://stackoverflow.com/questions/12469684/how-to-make-a-barplot-with-data-where-one-of-the-columns-already-contains-the-fr – Atticus29 Sep 18 '12 at 02:44