Dear all, I have a dataframe with a column representing the names of the elements (a, b, etc) and one with their frequencies. How can I plot the frequencies so that each element has an associated frequency value? I have been thinking of a histogram, but I have found it difficult to implement. I have tried the following:
group <- c("a", "b", "c", "d", "e") freq <-c(1, 2, 2, 5, 3) df <- data.frame(group, freq, stringsAsFactors = FALSE) hist(df$freq) library(lattice) histogram( ~ df$group) histogram( ~ as.factor(df$group)) histogram(df$freq ~ as.factor(df$group)) hist(df$freq) returns a histogram in which the values 1 and 2 appear 3 times, the values 3 and 5 appear once and 4 never. This is not what I wanted; I want instead a graph telling me that a appears once, b twice etc. histogram( ~ df$group) gives the error: Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE, include.lowest = include.lowest, : negative length vectors are not allowed histogram( ~ as.factor(df$group)) and histogram(df$freq ~ as.factor(df$group)) report all groups on the x axis (that is good) but all at 20% level. What am I missing? Thank you. -- Best regards, Luigi ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.