ggplot2 geom_bar issue

So I want to create a bar plot of the top 6 most frequent countries. My issue is the scaling of the counts. I want to represent the counts to what shows in the data.frame I created from the head() that I sorted by frequency. Here's what I've done so far:

top_countries <-head(sort(table(rdf$geo_country), decreasing = TRUE))
top_countries <- data.frame(top_countries)
colnames(top_countries) <- c("Country", "Frequency")

Could you please turn this into a proper minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

Hi @casanoan,

I don't understand what the question is - it seems like you have created the plot you refer to.

Sorry everybody! I guess my question wasn't very specific. I eventually figured out what I was trying to do. I didn't like the frequency scale in scientific notation. I wanted to label each bar with the frequencies from the table. My issue now is how do I remove the column NA. I tried na.rm() but I think the best option is to drop the vector entirely. This is what I have now:

Generating a table and converting it back to a dataframe is not the best approach, we could easily give you a better alternative but we would need you to provide sample data on a copy/paste friendly format (as explained in the reprex guide I gave you before)

If you want to go all base R, here's a suggestion. I assume that the original Country column is called "country":

top_countries = rdf[!$country),]
top_countries = top_countries[order(top_countries$geo_country, decreasing=T),][1:6,]
colnames(top_countries) <- c("Country", "Frequency")

Of course, this can be done more elegantly with tinyVerse/dplyr

rdf %>% filter(! %>% arrange(desc(geo_country)) %>% rename(Country=country, Frequency=geo_country) %>% top_n(6)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.