Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a barplot with data where one of the columns already contains the frequencies/counts
    primarykey
    data
    text
    <p>I'm trying to plot the number of samples that have data for for each of several traits. I actually already have a column of data containing these numbers of samples, and was simply hoping to plot it as the "frequency". As it is, I'm not quite sure where the frequency data is coming from (see code below). Please let me know whether I can clarify anything. Many thanks!:</p> <pre><code>##my data data&lt;-structure(list(V1 = structure(c(2L, 1L), .Label = c("593", "QnWeight_initial" ), class = "factor"), V2 = structure(c(2L, 1L), .Label = c("566", "Head"), class = "factor"), V3 = structure(c(2L, 1L), .Label = c("535", "V1"), class = "factor"), V4 = structure(c(2L, 1L), .Label = c("535", "V2"), class = "factor"), V5 = structure(c(2L, 1L), .Label = c("535", "V3"), class = "factor"), V6 = structure(c(2L, 1L), .Label = c("482", "Left_Leg"), class = "factor"), V7 = structure(c(2L, 1L), .Label = c("474", "Left_Antenna"), class = "factor"), V8 = structure(c(2L, 1L), .Label = c("237", "Qn_Weight_Loss"), class = "factor"), V9 = structure(c(2L, 1L ), .Label = c("230", "Days_wrkr_eclosion"), class = "factor"), V10 = structure(c(2L, 1L), .Label = c("81", "Growth_all"), class = "factor"), V11 = structure(c(2L, 1L), .Label = c("79", "Growth_1_2"), class = "factor"), V12 = structure(c(2L, 1L), .Label = c("62", "Growth_1_3"), class = "factor"), V13 = structure(c(2L, 1L), .Label = c("60", "Growth_2_3"), class = "factor"), V14 = structure(c(2L, 1L), .Label = c("51", "Right_Antenna" ), class = "factor"), V15 = structure(c(2L, 1L), .Label = c("49", "Left_Leg_Remeasure"), class = "factor"), V16 = structure(c(2L, 1L), .Label = c("49", "Right_Leg"), class = "factor"), V17 = structure(c(2L, 1L), .Label = c("47", "Head_Remeasure"), class = "factor"), V18 = structure(c(2L, 1L), .Label = c("46", "Left_Antenna_Remeasure" ), 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)) dat&lt;-data.frame(fac=unlist(data[1,, drop=FALSE]), freqs=unlist(data[2,, drop=FALSE])) t&lt;-table(rep(as.character(dat[, 1]), dat[, 2])) ##the plot I'm making at the moment barplot(t, main="Sample Sizes of Various Fitness Traits", xaxt='n', xlab='', width=0.85) labels&lt;-unlist(data[1,,drop=FALSE]) text(1:18, par("usr")[3] -0.25, srt=90, adj=1,labels=labels,xpd=TRUE, cex=0.6) ##The kind of plot I'm looking to make par(las=2) # make label text perpendicular to axis par(mar=c(5,8,4,2)) # increase y-axis margin. print(mtcars$gear) counts &lt;- table(mtcars$gear) print(counts) barplot(counts, main="Car Distribution", names.arg=c("3 Gears", "4 Gears", "5   Gears"), cex.names=0.8) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload