In: Computer Science
How do you graph integers in r studio. I made new data frames for specific parts of the data I wanted to use and then got the sum of a column and saved it as a variable under values. My goal is to know how to graph these integer values in a barplot comparing all the values.
Program to print sum of specific column.
df<- data.frame(group=rep(c("Men", "Women"),each=6),
fruit=rep(c("Apple", "Kiwi", "Grapes", "Banana",
"Pears", "Orange"),2),
people=c(22, 10, 15, 23, 12, 18, 18, 5, 15, 27,
8, 17))
add=sum(df$people)
print(add)
Output: - here Output Show some of people column.
Program to barplot integer values: -(makes sure are you install ggplot2 library in your system)
df<- data.frame(group=rep(c("Men", "Women"),each=6),
fruit=rep(c("Apple", "Kiwi", "Grapes", "Banana",
"Pears", "Orange"),2),
people=c(22, 10, 15, 23, 12, 18, 18, 5, 15, 27,
8, 17))
library(ggplot2)
ggplot(survey, aes(x=fruit, y=people, fill=group)) +
geom_bar(stat="identity")
Output: -