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)

Error in Summary.factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : ‘sum’ not meaningful for factors

  • $\begingroup$ 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" $\endgroup$ – keiv.fly Dec 5 '18 at 21:04
  • $\begingroup$ 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. $\endgroup$ – Chris Kehl Dec 5 '18 at 21:20

The following code :


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

  • $\begingroup$ working on histogram hist(data$Freq) $\endgroup$ – Chris Kehl Dec 5 '18 at 23:22
  • $\begingroup$ not looking as expected. $\endgroup$ – Chris Kehl Dec 5 '18 at 23:24
  • 1
    $\begingroup$ barplot(table(country$continent)) $\endgroup$ – keiv.fly Dec 5 '18 at 23:29
  • $\begingroup$ Closing in on this problem, thanks, it did look 100% better. $\endgroup$ – Chris Kehl Dec 5 '18 at 23:40
  • 1
    $\begingroup$ 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) $\endgroup$ – keiv.fly Dec 6 '18 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.