# error trying to build a histogram using r with the rStudio application

Using ggplot2 I am attempting to create a histogram. I have a column that is full on the continents. I need to add all the continents which I attempted to do with the aggregate function.

data <- aggregate(country$continent,country["continent"], sum) hist(data)  Error in Summary.factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : ‘sum’ not meaningful for factors • I do not understand what you want to achieve. You currently group by continent and sum continent names for each country. You cannot do "USA" + "Russia" = "Love" – keiv.fly Dec 5 '18 at 21:04 • Ok I have a data_frame called country which has a column called continent. I wish to groupby and count the continent column. So, for example USA = 5, Russia = 2, etc. After that is done, I am going to make a histogram. – Chris Kehl Dec 5 '18 at 21:20 ## 1 Answer The following code : data.frame(table(country$continent))


will create a dataframe where one column is the continent and the other is the number of countries in the continent.

• working on histogram hist(data$Freq) – Chris Kehl Dec 5 '18 at 23:22 • not looking as expected. – Chris Kehl Dec 5 '18 at 23:24 • barplot(table(country$continent)) – keiv.fly Dec 5 '18 at 23:29
• Closing in on this problem, thanks, it did look 100% better. – Chris Kehl Dec 5 '18 at 23:40
• Histogram is not a barplot. data['percen'] creates another column in the same dataframe. Calling hist(data) means you want to create a frequency histogram from the data frame. And data frame is not one column but many. So what you want is probably barplot(data$Freq/sum(data$Freq)) or barplot(data\$percen) – keiv.fly Dec 6 '18 at 14:39