r - how to Create Histogram for one variable, using another to determine its frequency? -
i'm new r, , using histograms first time. need construct histogram chart show frequency of income 50 united states + district of columbia.
this data given me:
> data x.income. x.no.states. 1 -22.024 5 2 -25.027 13 3 -28.030 16 4 -31.033 9 5 -34.036 4 6 -37.039 2 7 -40.042 2 > hist(data$x.income, col="red")
but produces histogram of number of frequency each income amount appears in graph, not number of states have level of income. how account number of states have each level of income in chart?
use bar plot instead of histogram, histogram expects calculate frequencies you:
library(ggplot2) # make data exercise income = c(-22.024, -25.027, -28.030, -31.033, -34.036, -37.039,-40.042) freq = c(5,13,16,9,4,2,2) df <- data.frame(income, freq) df <- names(c("income","freq")) # graph object p <- ggplot(data=df) + aes(x=income, y=freq) + geom_bar(stat="identity", fill="red") # call object view p
Comments
Post a Comment